有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?
我知道实验性多Poco查询,但在我看来它们非常复杂,并不是我想要的东西。
答案 0 :(得分: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");
答案 1 :(得分: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")