mapping complex class with NPOCO
Asked Answered
R

1

6

Is it possible to map a complex class with both a nested class and a collection class with NPoco? I've had a look at the documentation but it's not 100% clear whether i can map to this class with one query.

For example given these classes:

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; }
}

Would it be possible to map the User and populate the Address property and the Cars property with one query?

I've seen i can do a OneToMany Fetch, and that it's also possible to map a property which is a class, but i'm not certain if i can map a class with both of these with one fetch.

Rolfe answered 14/1, 2014 at 21:50 Comment(0)
L
0

Its not really possible. I would map to a flattened DTO first then perform a LINQ query to get it into your above model.

Limnology answered 6/8, 2014 at 12:39 Comment(1)
Could you please update your answer to match current behavior? github.com/schotime/NPoco/wiki/Mapping-to-Nested-ObjectsAngulate

© 2022 - 2024 — McMap. All rights reserved.