0
我想將單個查詢的多個集合(一對多引用)映射到對象中。目的是這樣的:Dapper - 使用單個查詢映射多個一對多
public class Item {
public int Id { get; set; }
public string Name { get; set; }
public List<ItemDetail> Details { get; set; }
public List<ItemHistory> Histories { get; set; }
public List<ItemOrder> Orders { get; set; }
}
我創建了返回我我想要的一切單個查詢,如下所示:
SELECT
i.[Id], i.[Name],
detail.[Id] ItemDetailId, detail.[Description] ItemDetailDescription,
history.[Id] ItemHistoryId, history.[Date] ItemHistoryDate,
history.[Description] ItemHistoryDescription,
order.[Id] ItemOrderId, order.[Date] ItemOrderDate, order.[Quantity] ItemOrderQuantity
FROM
[dbo].[Items] i
inner join [dbo].[ItemDetails] detail on i.[Id] = detail.[ItemId]
inner join [dbo].[ItemHistories] history on i.[Id] = history.[ItemId]
inner join [dbo].[ItemOrders] order in i.[Id] = order.[ItemId]
好吧,我已經通過的NuGet添加和小巧玲瓏Query
擴展方法不允許我在一行中映射多個類型。我如何通過Dapper.NET將上面的查詢映射到上面的對象中?
謝謝你們!
請添加ItemDetail,ItemHistory,ItemOrder類。 –