映射许多表与一个对象的一对多关系

时间:2012-06-14 10:23:53

标签: .net one-to-many fluent-interface entity-framework-4.3

我正在尝试弄清楚如何使用Fluent API将以下数据库表映射到我的域模型。它有可能吗?

我在数据库中拥有的内容:

table Person
{ Id
  Name
  Surname }

table Contact
{ Id
  PersonId
  ContactType
  ContactDesc }

e.g. of the data: 
Person {Id: 1, Name: "John", Surname: "Sutherland"}
Contact {Id: 1, PersonId: 1, ContactType: "Work", ContactDesc: "000 0000 000"}
Contact {Id: 2, PersonId: 1, ContactType: "Home", ContactDesc: "000 0000 001"}
Contact {Id: 3, PersonId: 1, ContactType: "Cell", ContactDesc: "000 0000 002"}

我的域名模型:

public class Person
{
  public int Id { get; set; }
  public string Name { get; set; }
  public string Surname { get; set; }
  public string WorkTelephoneNumber { get; set; }
  public string HomeTelephoneNumber { get; set; }
  public string CellphoneNumber { get; set; }
}

目前我正在使用Fluent映射到单独的Person和Contact POCO,然后手动将其展平为我的Domain模型。我正试图摆脱额外的POCO层并直接映射到我的域模型。

我很感激帮助!

0 个答案:

没有答案
相关问题