Mapping data from 2 tables to 1 entity - Entity Framework 4

后端 未结 2 911
花落未央
花落未央 2020-12-16 06:25

I am stuck here.

Is it possible to map data from 2 different tables to 1 entity in Entity Framework 4.

I have a bunch of employees in one table, and in the o

相关标签:
2条回答
  • 2020-12-16 06:58

    The reasons for doing this are quite straightforward - for example, a table of data points that all have one of five 'types'. Obviously the 'type' will be a separate table for the sake of normalisation, but from an application point of view (working with the data) it makes more sense to have all properties in a single entity.

    So we can't do this with Entity Framework - a supposed Object-Relational-Mapper. What, then, is the point of using such a framework?

    0 讨论(0)
  • 2020-12-16 07:15

    You cannot map two tables with a one-to-many relationship to one entity. If you don't want projecting the results into one object in code, consider creating a view and mapping it instead.

    According to http://msdn.microsoft.com/en-us/library/bb896233.aspx

    You should only map an entity type to multiple tables if the following conditions are true:

    • The tables to which you are mapping share a common key.

    • The entity type that is being mapped has entries in each underlying table. In other words, the entity type represents data that has a one-to-one correspondence between the two
      tables; the entity type represents an inner join of the two tables.

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