entity framework - EF Migration Clear Cache -
public class { public int id { get; set; } public virtual icollection<ahistory> ahistorys { get; set; } } public class ahistory { public int aid { get; set; } public virtual a {get; set; } }
i renammed ahistories ahistory.
add-migration histomig
ahistories: entitytype: entityset 'ahistories' based on type 'ahistory' has no keys defined.
so error mention old name no longer exists in solution.
what should ?
i've clean visual studio solution no effects.
i tried comment out navigation property, add migration, rollback migration, uncomment add migration ; still erros.
i've done search through vs solution on string "ahistories" 0 occurence found.
based on esg comment, i've added :
public class defaultcontext : dbcontext { protected override void onmodelcreating(dbmodelbuilder modelbuilder) { modelbuilder.configurations.add(new ahistorymapping()); public dbset<ahistory> ahistorys { get; set; } } } public class ahistorymapping : entitytypeconfiguration<ahistory> { public ahistorymapping() { haskey(ah => ah.aid); } }
it works !
edit
actually doesn't "work"... compiles result not expecting.
this code creates table unique identifier named fundid , foreign key named fund_id.
i've change code
public class ahistorymapping : entitytypeconfiguration<ahistory> { public ahistorymapping() { hasrequired(ah => ah.a) .withmany(a => a.ahistorys) .hasforeignkey(ah => ah.aid); } }
it doesn't compile anymore. message again.
ahistory: : entitytype 'ahistory' has no key defined. define key entitytype. ahistorys: entitytype: entityset 'ahistorys' based on type 'ahistory' has no keys defined.
edit 2
it turns out ef require primary key. here solution :
public class ahistorymapping : entitytypeconfiguration<ahistory> { public ahistorymapping() { haskey(ah => new { ah.aid, ah.date }); hasrequired(ah => ah.a) .withmany(a => a.ahistorys) .hasforeignkey(ah => ah.aid); } }
Comments
Post a Comment