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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -