asp.net - Entity Framework Code First Foreign Key different column key -


so, addresses has pk of id , foreign key of entitykey references vendors table's id, because vendors have addresses physical buildings.

when query vendors, i'm not able return associated address.

note: don't want change schema.

[table("ee.address")] public partial class address {     [key]     public guid id { get; set; }      [stringlength(50)]     public string address1 { get; set; }      [stringlength(50)]     public string address2 { get; set; }      [stringlength(50)]     public string city { get; set; }      [stringlength(5)]     public string state { get; set; }      [stringlength(30)]     public string postalcode { get; set; }      [stringlength(10)]     public string countrycode { get; set; }      public guid entitykey { get; set; }      [foreignkey("entitykey")]      public virtual vendor vendor { get; set; }     // entitykey should vendor.id }   [table("ee.vendor")] public partial class vendor {     [key]     public guid id { get; set; }      [stringlength(50)]     public string name { get; set; }      [stringlength(50)]     public string alternativename { get; set; }      [stringlength(50)]     public string vendorcode { get; set; }      [stringlength(50)]     public string taxid { get; set; }      public guid vendortypekey { get; set; }      public guid? parentkey { get; set; }      [foreignkey("id")]     public virtual address address { get; set; } } 

try this:

[table("ee.address")] public partial class address {     [key]     public guid id { get; set; }      [stringlength(50)]     public string address1 { get; set; }      [stringlength(50)]     public string address2 { get; set; }      [stringlength(50)]     public string city { get; set; }      [stringlength(5)]     public string state { get; set; }      [stringlength(30)]     public string postalcode { get; set; }      [stringlength(10)]     public string countrycode { get; set; }      [foreignkey("vendor")]     public guid entitykey { get; set; }      public virtual vendor vendor { get; set; }     // entitykey should vendor.id }   [table("ee.vendor")] public partial class vendor {     [key]     public guid id { get; set; }      [stringlength(50)]     public string name { get; set; }      [stringlength(50)]     public string alternativename { get; set; }      [stringlength(50)]     public string vendorcode { get; set; }      [stringlength(50)]     public string taxid { get; set; }      public guid vendortypekey { get; set; }      public guid? parentkey { get; set; }      [foreignkey("address")]     public guid addressid {get; set; }      public virtual address address { get; set; } } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -