Entity Framework 4: Can you duplicate an entity and alter it based on filter condition
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.
精彩评论