entity framework - Getting multiple errors during Database-Migration with EF6 and .NET 4.6.1 -
getting following errors:
"validation failed 1 or more entities. see 'entityvalidationerrors' property more details." @ line 89 of configuration.cs
line 89 context.savechanges();
, @ end of class file:
namespace model.migrations { using system; using system.data.entity; using system.data.entity.migrations; using system.linq; internal sealed class configuration : dbmigrationsconfiguration<model.applicationdbcontext> { public configuration() { automaticmigrationsenabled = false; } protected override void seed(applicationdbcontext context) { seeddata.additionalseed _additionalseed = new seeddata.additionalseed(); _additionalseed.seed_stateorprovince(context); _additionalseed.seed_countryorregion(context); _additionalseed.seed_contacttypes(context); _additionalseed.seed_currencycodes(context); _additionalseed.seed_preferences_calendarsettings_calendarview(context); _additionalseed.seed_preferences_calendarsettings_weeklyview(context); _additionalseed.seed_preferences_calendarsettings_whattoshow(context); _additionalseed.seed_preferences_calendar_futurepastsettings(context); _additionalseed.seed_preferences_itemsandinventory_advancedinventory_barcodes_copybarcodefrom(context); _additionalseed.seed_preferences_itemsandinventory_unitofmeasuretype(context); _additionalseed.seed_preferences_payrollemployees_employeedefaults_payfrequency(context); _additionalseed.seed_preferences_payrollemployees_employeedefaults_sickandvacationdefaults_accuralperiod(context); _additionalseed.seed_preferences_payrollemployees_employeedefaults_taxes_filingstatus(context); _additionalseed.seed_preferences_reportsandgraphs_reportpreferences_datepreparedformat(context); _additionalseed.seed_preferences_reportsandgraphs_reportpreferences_pagenumberformat(context); _additionalseed.seed_preferences_reportsandgraphs_reportpreferences_pagelayout(context); _additionalseed.seed_preferences_salesandcustomers_invoicepackingslip(context); _additionalseed.seed_preferences_salesandcustomers_roundingrules(context); _additionalseed.seed_preferences_salesandcustomers_shippers(context); _additionalseed.seed_preferences_salestax_intervals(context); _additionalseed.seed_preferences_salestax_salestaxcode(context); _additionalseed.seed_preferences_sendforms_sendmethod(context); _additionalseed.seed_preferences_sendforms_deliverymethod(context); _additionalseed.seed_preferences_sendforms_emailtemplatecategorylist(context); _additionalseed.seed_preferences_timeandexpenses_workweek(context); _additionalseed.seed_security_rolemaster(context); context.savechanges(); _additionalseed.seed_security_accountingrole(context); _additionalseed.seed_security_bankingrole(context); _additionalseed.seed_security_centersrole(context); _additionalseed.seed_security_companyrole(context); _additionalseed.seed_security_customerandreceivablesrole(context); _additionalseed.seed_security_employeesandpayrollrole(context); _additionalseed.seed_security_filerole(context); _additionalseed.seed_security_listsrole(context); _additionalseed.seed_security_reportsrole(context); _additionalseed.seed_security_sitesettingsrole(context); _additionalseed.seed_security_timetrackingrole(context); _additionalseed.seed_security_vendorsandpayablesrole(context); _additionalseed.seed_taxesfilingstatus(context); _additionalseed.seed_employmenttype(context); _additionalseed.seed_employeeemergencycontacttype(context); _additionalseed.seed_employeeethnicity(context); _additionalseed.seed_employeemaritalstatus(context); _additionalseed.seed_salutations(context); _additionalseed.seed_defaultunitusedfortypes(context); _additionalseed.seed_unitofmeasuredefaulttype(context); context.savechanges(); _additionalseed.seed_unitofmeasuredefaultbaseunits(context); context.savechanges(); _additionalseed.seed_unitofmeasuredefaultrelatedunits(context); context.savechanges(); _additionalseed.seed_terms(context); _additionalseed.seed_taxforms(context); context.savechanges(); _additionalseed.seed_taxformdetail(context); _additionalseed.seed_accounttypes(context); context.savechanges(); _additionalseed.seed_industries(context); context.savechanges(); _additionalseed.seed_organizationtypes(context); context.savechanges(); } } }
when comment line out following error:
"sequence contains more 1 element" @ line 12 of taxformdetail.cs
the code class file on 1200 lines supply unique lines:
namespace model.migrations.seeddata { using system; using system.data.entity; using system.data.entity.migrations; using system.linq; public partial class additionalseed { public void seed_taxformdetail(applicationdbcontext context) { context.taxformdetail.addorupdate( r => new { r.taxformid, r.taxcodelinedescription }, new taxformdetailmodel() { taxcodelinenumber = null, taxcodelinedescription = "schedule f: interest expense, mortgage", taxformid = context.taxforms.firstordefault(r => r.taxform.equals("1040")).recordid }, ..... new taxformdetailmodel() { taxcodelinenumber = null, taxcodelinedescription = "pt i-unrel bus inc: sch c, l3-inc-real/pers prop", taxformid = context.taxforms.firstordefault(r => r.taxform.equals("990-t")).recordid } ); } } }
my model table follows:
[table(name: "taxformdetail")] public class taxformdetailmodel { [key, required, databasegenerated(databasegeneratedoption.identity)] public guid recordid { get; set; } public guid taxformid { get; set; } public string taxcodelinenumber { get; set; } [maxlength(255)] public string taxcodelinedescription { get; set; } }
i have read numerous google , results on these errors , nothing helps unless have missed something.
edit
the error have stack trace run package manager, there no other way know of of getting else:
system.invalidoperationexception: sequence contains more 1 element @ system.linq.enumerable.singleordefault[tsource](ienumerable`1 source) @ system.data.entity.core.objects.elinq.objectqueryprovider.<getelementfunction>b__2[tresult](ienumerable`1 sequence) @ system.data.entity.core.objects.elinq.objectqueryprovider.executesingle[tresult](ienumerable`1 query, expression queryroot) @ system.data.entity.core.objects.elinq.objectqueryprovider.system.linq.iqueryprovider.execute[tresult](expression expression) @ system.data.entity.internal.linq.dbqueryprovider.execute[tresult](expression expression) @ system.linq.queryable.singleordefault[tsource](iqueryable`1 source, expression`1 predicate) @ system.data.entity.migrations.dbsetmigrationsextensions.addorupdate[tentity](dbset`1 set, ienumerable`1 identifyingproperties, internalset`1 internalset, tentity[] entities) @ system.data.entity.migrations.dbsetmigrationsextensions.addorupdate[tentity](idbset`1 set, expression`1 identifierexpression, tentity[] entities) @ model.migrations.seeddata.additionalseed.seed_taxformdetail(applicationdbcontext context) in z:\_profile storage\projects\corporate.web\model\migrations\seeddata\taxformdetail.cs:line 12 @ model.migrations.configuration.seed(applicationdbcontext context) in z:\_profile storage\projects\corporate.web\model\migrations\configuration.cs:line 81 @ system.data.entity.migrations.dbmigrationsconfiguration`1.onseed(dbcontext context) @ system.data.entity.migrations.dbmigrator.seeddatabase() @ system.data.entity.migrations.infrastructure.migratorloggingdecorator.seeddatabase() @ system.data.entity.migrations.dbmigrator.upgrade(ienumerable`1 pendingmigrations, string targetmigrationid, string lastmigrationid) @ system.data.entity.migrations.infrastructure.migratorloggingdecorator.upgrade(ienumerable`1 pendingmigrations, string targetmigrationid, string lastmigrationid) @ system.data.entity.migrations.dbmigrator.updateinternal(string targetmigration) @ system.data.entity.migrations.dbmigrator.<>c__displayclassc.<update>b__b() @ system.data.entity.migrations.dbmigrator.ensuredatabaseexists(action mustsucceedtokeepdatabase) @ system.data.entity.migrations.infrastructure.migratorbase.ensuredatabaseexists(action mustsucceedtokeepdatabase) @ system.data.entity.migrations.dbmigrator.update(string targetmigration) @ system.data.entity.migrations.infrastructure.migratorbase.update(string targetmigration) @ system.data.entity.migrations.design.toolingfacade.updaterunner.run() @ system.appdomain.docallback(crossappdomaindelegate callbackdelegate) @ system.appdomain.docallback(crossappdomaindelegate callbackdelegate) @ system.data.entity.migrations.design.toolingfacade.run(baserunner runner) @ system.data.entity.migrations.design.toolingfacade.update(string targetmigration, boolean force) @ system.data.entity.migrations.updatedatabasecommand.<>c__displayclass2.<.ctor>b__0() @ system.data.entity.migrations.migrationsdomaincommand.execute(action command) sequence contains more 1 element
i figured out workaround situation.
for "validation failed 1 or more entities. see 'entityvalidationerrors' property more details." @ line 89 of configuration.cs error, changed seed method check existing data specific table (tax code) , if table empty, add records not add or update.
as far "sequence contains more 1 element" @ line 12 of taxformdetail.cs goes, did same thing.
now every time update-database pm command, not more errors.
Comments
Post a Comment