Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework map multiple tables to one entity

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?

like image 277
Jacob Adams Avatar asked Nov 20 '09 17:11

Jacob Adams


3 Answers

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

like image 108
Matt Dotson Avatar answered Oct 20 '22 18:10

Matt Dotson


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

like image 30
Devart Avatar answered Oct 20 '22 18:10

Devart


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

like image 31
JKJKJK Avatar answered Oct 20 '22 19:10

JKJKJK