小巧玲珑直接返回一个子集特定的列到DTO [英] Dapper returning a sub set of specific columns directly into DTO
本文介绍了小巧玲珑直接返回一个子集特定的列到DTO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以直接短小精悍返回数据到一个DTO / POCO,只有具有域的一个子集 - 也就是说,我可以用它不包含在数据库表中的所有列类?
Can Dapper return data directly into a DTO/POCO that only has a subset of fields - ie can I it use classes that do not contain all the columns in the db tables?
例如,如果我有以下查询(原谅我的SQL - 不是我的强项):
Eg if I have the following query (excuse my sql - not my strong point):
select c.Name as "Customer", o.Number as "OrderNo", ol.Number as "Line", p.Description as "Product", ol.Qty
from order o
join customer c on c.Id = o.CustomerId
join orderLine ol on ol.OrderID = o.Id
join product p on p.Id = ol.ProductId
where o.date >= 1/9/2013 and o.date <= 30/9/2013
我如何使用小巧精致的阅读本到一个数组/下面的类的IEnumerable的:
How can I use Dapper to read this into an array/IEnumerable of the following class:
class CustOrders{
string Customer {get;set;}
integer Order {get;set;}
string Line {get;set;}
string Product {get;set;}
integer Qty {get; set;}
}
谢谢 蒂姆·
Thanks Tim
推荐答案
你可以做以下
var sql = @"select c.Name as [Customer], o.Number as [Order], ol.Number as [Line], p.Description as [Product], ol.Qty ...";
var result = connection.Query<CustOrders>(query);
这篇关于小巧玲珑直接返回一个子集特定的列到DTO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文