开发者

Model a 1-to-many relationship with a single table in Entity Framework

开发者 https://www.devze.com 2023-03-11 19:38 出处:网络
Lets say I have 2 tables on开发者_如何转开发 my physical model, Receipt(ID, Location) and LineItem(ID, ReceiptID, ItemName) where a Receipt has multiple LineItems and ReceiptID is a Foreign Key to Rec

Lets say I have 2 tables on开发者_如何转开发 my physical model, Receipt(ID, Location) and LineItem(ID, ReceiptID, ItemName) where a Receipt has multiple LineItems and ReceiptID is a Foreign Key to Receipt's ID.

I want to model these as a single table in my conceptual model, where I only see a table of LineItems with the Location included on each LineItem.

Every time I try to model this in the Entity Modeler, I get an error about how the Primary Key must be the same for every table being combined into the single conceptual entity.

Is this even possible to model using the entity framework?

Thanks!


No there is no way to model this directly. You must either create database view and map that view or import both entities and create QueryView in the model. In both cases resulting entity combining your two tables will become readonly and the only way to support CUD operations will be mapping stored procedures.

0

精彩评论

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