7

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?

5 Answers 5

6

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

Sign up to request clarification or add additional context in comments.

Comments

5

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

2 Comments

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.
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.
1

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."

1 Comment

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.
0

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.

Comments

0

A good way to do one entity that shares multiple tables is to use Entity Splitting. MSDN has a very simple tutorial that walks you through the process which is very easy, however, you may need to reshape your data model: http://msdn.microsoft.com/en-us/data/jj715646.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.