1

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

我可以做这样的事情吗?

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

基本上,PetaPoco 是否知道如何处理包含其他 Poco 的 Pocos?

我知道 Experimental Multi-Poco Queries,但在我看来它们相当复杂,并不是我想要的。

4

2 回答 2

2

我认为您需要做的就是添加第二种类型 (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");
于 2012-03-12T20:10:56.303 回答
1

然而这有效,但不支持分页

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")
于 2012-03-13T09:23:20.447 回答