views:

546

answers:

4

I have a database with a table for active orders and one for inactive orders. I would like to model this in Entity Framework as one entity called Orders. I also need a way to determine if an order in this collection is active or not, preferably by having a status property on the entity that is set according to what table it is in. Is there anyway to do this using Entity Framework 1. What about in Entity Framework 4?

A: 

If I am understanding you correctly both active and inactive orders would share the same properties (for example: both would have a decimal "amount" property) if this is the case then in EF 1, I am pretty certain this is not possible. I think you will have to fall back to Mapping your entities to a POCO Orders object.

Anthony
+1  A: 

Take a look at the Table Per Concrete Type inheritance.
It is described here in ADO.NET Team Blog.

Devart
This doesn't appear to be what I need. In that example, they made a separate DiscontinuedProducts entity. I want to use one Order entity but have it contain the data from two different tables.
Jacob Adams
Try the DefiningQuery approach.Write DefiningQuery with UNION and add an expression column returning the type of order. Please make sure that primary key types coincide.In case you need an opportunity to modify the entities, write necessary modification functions. For this you can either use CommandText, or write the procedures in your DB.
Devart
A: 

I think this is what you are looking for: How to: Define a Model with Multiple Entity Sets per Type (Entity Framework)

"The Entity Data Model (EDM) allows an entity type to be included by multiple entity sets within a single entity container or for an entity type to be included in entity sets in multiple entity containers. Defining multiple entity sets per type (MEST) allows users to streamline their code when databases have partitioning or other such scenarios where multiple tables have the same structure."

JKJKJK
I saw this article before. However this doesn't quite cover what I need. Although the Customer entity contains data from the CustomerWest and CustomerEast table, you can't go back later and look at a customer and determine its region. In my case I need a way to look at an Order and tell if it is active or not.
Jacob Adams
+1  A: 

You could create a view in your DB and generate the entity from that.

Matt Dotson