I am using PetaPoco v5.1.228.0 and I am trying to fetch a list of people along with the category they belong to, using paging (30 items per page).
This is my code:
IEnumerable<Person> people;
var sql = new Sql("SELECT * FROM Person p INNER JOIN Category c ON p.CategoryId = c.Id");
using (var db = GetDatabaseConnection()) {
var paging = db.Page<Person>(currentPage, 30, sql);
people = paging.Items;
}
Person.cs
public class Person {
public int Id { get; set; }
public string Name { get; set; }
public int CategoryId { get; set; }
public Category Category { get; set; }
}
Category.cs
public class Category {
public int Id { get; set; }
public string Name { get; set; }
}
The problem is it won't populate the Category property within the Person object. As far as I know only db.Fetch
allows multiple types to be specified, but in this case I would need to code the paging functionality myself.
What would be the best way to do it?
You can do it with an extention metod over IDatabase: