entity framework - EF Code First One-To-One with Join Table -
i trying configure model existing database, , running problem. previous developer modeled one-to-one relationship using join table. if have following classes , database structure below, how can map using code first?
public class title { public property property { get; set; } } public class property { public title titleinsurance { get; set; } } tbtitle -titleid = pk tbpropertytotitle -titleid - fk tbtitle.titleid -propertid - fk tbproperty.propertyid tbproperty -propertyid = pk
code in vb.net here, should easy translate. mark primary keys key
data attribute. entity framework automatically properties named class + id, i.e. tbtitleid assign primary keys, since isn't applicable here, need key
attribute.
overridable
properties denote navigation properties. in c#, should equivalent virtual
properties. when navigation property accessed, entity framework automatically valid foreign key relations, , populate appropriate data.
for one-to-one relationship, entity framework expects 2 tables share same primary key, shown titleid here.
public class tbtitle <key()> public property titleid integer ... public overridable property property tbproperty end class public class tbproperty <key()> public property titleid integer ... public overridable property title tbtitle end class
Comments
Post a Comment