5

是否可以使用 NPoco 映射具有嵌套类和集合类的复杂类?我查看了文档,但我是否可以通过一个查询映射到这个类并不是 100% 清楚。

例如给定这些类:

public class User
{
  public int UserId { get; set; }
  public string Name { get; set; }
  public Address Address { get; set; }
  public List<Car> Cars { get; set; }
}

public class Address
{
  public string Street { get; set; }
  public string City { get; set; }
}

public class Car
{
  public string Make { get; set; }
  public string Color { get; set; }
}

是否可以通过一个查询映射用户并填充地址属性和汽车属性?

我已经看到我可以进行 OneToMany Fetch,并且也可以映射作为类的属性,但我不确定我是否可以通过一次提取来映射具有这两种属性的类。

4

1 回答 1

0

它真的不可能。我会先映射到一个扁平化的 DTO,然后执行一个 LINQ 查询以将其放入您的上述模型中。

于 2014-08-06T12:39:43.190 回答