MikeSW
MikeSW

Reputation: 16358

Can Peta Poco map to complex types?

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.

Upvotes: 1

Views: 2585

Answers (2)

MikeSW
MikeSW

Reputation: 16358

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")

Upvotes: 1

Typo Johnson
Typo Johnson

Reputation: 6044

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");

Upvotes: 2

Related Questions