Entity Framework map multiple tables to one entity

前端 未结 5 708
抹茶落季
抹茶落季 2021-01-18 04:50

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 t

相关标签:
5条回答
  • 2021-01-18 05:01

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

    0 讨论(0)
  • 2021-01-18 05:16

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

    0 讨论(0)
  • 2021-01-18 05:23

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

    0 讨论(0)
  • 2021-01-18 05:27

    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.

    0 讨论(0)
  • 2021-01-18 05:27

    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

    0 讨论(0)
提交回复
热议问题