c# - Entity Framework Core still picks up old column -
i delete column conversationid
tables. when start debug service , try save getting error:
invalid column name 'conversationid'.
code:
public class astootcontext : dbcontext { public astootcontext(dbcontextoptions<astootcontext> options) : base(options) { } protected override void onmodelcreating(modelbuilder modelbuilder) { } public dbset<servicerequest> servicerequests { get; set; } }
and entity looks this:
public class servicerequest { public int id { get; set; } public int senderuserid { get; set; } public int pricetypeid { get; set; } public decimal price { get; set; } public bool isaccepted { get; set; } public datetime created { get; set; } public int messageid { get; set; } }
all references conversationid
removed code, i've rebuilt, yet i'm still getting error , don't understand why.
this sql server table can see there no conversationid
:
is there secret cache need delete or have run update this?
ef core code based orm, important here being m - mapper. doesn't matter actual database structure is, important ef *thinks** based on code model (entity classes , properties, combined data annotations, fluent configuration , set of conventions).
so problem should originate code. since you've removed explicit property, should caused shadow property. , explained in documentation link, shadow properties introduced convention relationships:
shadow properties can created convention when relationship discovered no foreign key property found in dependent entity class. in case, shadow foreign key property introduced.
the documentation explains naming rules applied in different scenarios.
a shadow property called conversationid
can introduced in several ways, according provided information, cause have entity class called conversation
defining one-to-many relationship servicerequest
having collection type navigation property:
public class conversation { public int id { get; set; } // ... public icollection<servicerequest> servicerequests { get; set; } }
which according comment indeed case.
for completeness, here other possible scenarios generating such property:
(1) no collection navigation property in conversation
, reference navigation property in servicerequest
:
public class conversation { public int id { get; set; } // ... } public class servicerequest { // ... public conversation conversation { get; set; } }
(2) no navigation properties in conversation
, servicerequest
, fluent configuration:
modelbuilder.entity<conversation>() .hasmany<servicerequest>();
or
modelbuilder.entity<servicerequest>() .hasone<conversation>();
or variations of above.
(3) no relationship involved, shadow property created through fluent configuration:
modelbuilder.entity<servicerequest>() .property<int>("conversationid");
Comments
Post a Comment