开发者

Entity Framework 4: Can you duplicate an entity and alter it based on filter condition

开发者 https://www.devze.com 2023-01-23 10:13 出处:网络
Is there a way within the entity framework designer to duplicate an entity and then apply a filter condition to both to make them unique. Id like to retain all navigation properties and what not.

Is there a way within the entity framework designer to duplicate an entity and then apply a filter condition to both to make them unique. Id like to retain all navigation properties and what not.

For example, say in the database I had a table of orders. I could have two entities, one called IncompleteOrders and One called Complete based on the same table, with the complete having a filter specified on the database fi开发者_开发知识库eld 'complete'.

Thanks in advance


Yes, this is called Table per Hierachy

You have one physical table, which has a special, single, scalar column which is used as a discriminator.

Like this:

OrderId OrderName IsComplete
1       Foo       1
2       Bar       1
3       FooBar    0

Where IsComplete is the discriminator (BIT column, for example), so when you setup your entities on your EDMX, you create three entities:

1. Orders
2. CompleteOrders (derives from Orders)
3. InCompleteOrders (derives from Orders)

On the table mapping for Orders, you say "Maps to CompleteOrders, when IsComplete = 1", and "Maps to InCompleteOrders, when OrderType = 0".

Good writeup on TPH/Discriminator pattern here.

0

精彩评论

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

关注公众号