Question

Having 2 pocos

 public class ProductInfoModel
{
    public int Id { get; set; }
    public string Name { get; set; }        
    public ItemInfo Producer { get; set; }
}

public class ItemInfo
{
    public int Id {get;set;}
    public string Name {get;set;}
}

Can I do something like this?

var result=db.Query<ProductInfoModel>("select p.Id,p.Name,pr.Id as Producer_Id, pr.Name as Producer_Name from products p inner join producers pr on pr.Id=p.ProducerId")

Basically, does PetaPoco knows how to deal with Pocos containing other Poco?

I know about Experimental Multi-Poco Queries, but they seem to me pretty complicated and not quite the thing I want.

Was it helpful?

Solution 2

However this works, but no pagination support

var result=db.Query<ProductInfoModel,ItemInfo>(
 @"select p.Id,p.Name,pr.Id , pr.Name 
     from products p inner join producers pr on pr.Id=p.ProducerId")

OTHER TIPS

I reckon all you need to do is add the second type (ItemInfo) :

var result=db.Query<ProductInfoModel, ItemInfo>(
     "select p.Id,p.Name,pr.Id as Producer_Id, pr.Name as Producer_Name from products " +
     "p inner join producers pr on pr.Id=p.ProducerId");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top