c# - Entity Framework code first one-to-zero relationship -
i trying one-to-zero relationship between table staff , department.
public class staff { public int id { get; set; } // other fields [foreignkey("departmentid")] public int departmentid { get; set; } public virtual department department { get; set; } } public class department { [key] public int id { get; set; } public string name { get; set; } public virtual staff staff{ get; set; } }
when run code, gives error:
the property 'departmentid' cannot configured navigation property. property must valid entity type , property should have non-abstract getter , setter. collection properties type must implement icollection t valid entity type.
change model ,now can use departmentid foreign key
public class department { [key] public int departmentid { get; set; } public string name { get; set; } public virtual staff staff{ get; set; } }
Comments
Post a Comment