c# - Data annotations on EF entities suddenly stopped working -


i've inherited web application , data annotations used define relationships between entities stopped working.

i have tried various things , can't figure out why hoping here can point issue out.

the application uses sqlite database, , contains 3 (3) basic tables:

  • order
  • order_entry
  • order_client

the entity order looks this:

[table("order")] public class order {     [column("id")]     public int id { get; set; }      public virtual icollection<orderentry> orderentries { get; set; }      [foreignkey("id")]     public virtual orderclient orderclients { get; set; }      public order()     {         orderentries = new hashset<orderentry>();     } } 

nothing fancy. single order can contain many entries, single order can have single client.

the entity code order_entry looks this:

[table("order_entry")] public class orderentry {     [column("id")]     public int id { get; set; }      [column("order_id")]     public int orderid { get; set; }      [foreignkey("orderid")]     public virtual order order { get; set; } } 

again, nothing fancy. single entry can belong single order.

orderentries work well, , can basic includes, without issues:

ctx.orders.include(x => x.orderentries).tolist(); 

the problem, however, comes in order_client table, in many-to-one relationship order.

the order_client entity:

[table("order_client")] public class orderclient {     [column("id")]     public int id { get; set; }      [column("order_id")]     public int orderid { get; set; }      public virtual icollection<order> orders { get; set; }      public orderclient()     {         orders = new hashset<order>();     } } 

we've tried adding [foreignkey("orderid")] attribute "orders", throws exception saying property "orderid" cannot found on parent role "order".

if add [inverseproperty("orders")] attribute "orderid" property, exception thrown column orderclient_id cannot found in table.

the order_entry , order_client tables have foreign_key constraint order in database structure, made sure of this.

i stumped here. unfortunately, cannot move current instance of application fluent api change impact outweighs sla agreement, need fix current problem.

any ideas welcomed.

update

the original developer created client - order relationship incorrectly. stated order can have multiple clients, instance of single client having multiple orders.

i think missing concept of relationship. can find here. try go throught once , done. http://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-first.aspx


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -