开发者

EF model from 2 tables connected with junction table - Model don't see records and changes in junction table

I have several tables in my SQL2008 DB, Managers(ManagerID is a PK, incremental) and Customers(CustomerID is a PK, incremental) are among them. All ID columns are int. They are connected with junction table ManagersCustomers(fields: CustomerID is a PK, ManagerID) and there are relations: from CustomerID in Customers to same in junction table with delete cascade rule and from ManagerID in Managers to same in junction table with delete cascade too. So I have Managers 0..1 to * Customers relation in my edmx model after generating it from my DB and I can see this relation is mapped to junction table. I tested junction table in SQL Server Management Studio, it works correctly. Ok. In my app I have 2 parts - edmx model on server side connected with client side through WCF Data Service. In client part I'm creating instance of my entities class, and in debug mode I can watch entities class instance's data. Both entities Customers and Managers are filled with data correctly, but in navigation fields I can see only 0. For example I have Customer with CustomerID = 1 connected with Manager with ManagerID=3 and there is a record in junction ta开发者_StackOverflowble. So, if it would work correctly, I would see my manager in navigation field of Customers entity and same with customer nav field in Managers entity. But I can see only zeros.


The easiest thing to do is to change the ManagersCustomers table so that both columns are part of the PK, and then recreate your model. The GUI designer won't pick it up as a many-to-many association unless you do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜