C# 如何在带有SQL查询的dapper接口(IDBConnection)中使用automapper

C# 如何在带有SQL查询的dapper接口(IDBConnection)中使用automapper,c#,asp.net-mvc,.net-core,dapper,C#,Asp.net Mvc,.net Core,Dapper,public IEnumerable索引(字符串字、字符串分区码、字符串年标签、int pageno) { 使用(IDbConnection dbConnection=Connection) { var data=dbConnection.Query(@“选择替换(将NVARCHAR(10),fystart,6),”,“,-”)作为fystart, 替换(将(NVARCHAR(10),fyend,6),“,”-”)从fydates转换为fyend,其中yearlabel=@yearlabel“,

public IEnumerable索引(字符串字、字符串分区码、字符串年标签、int pageno)
{
使用(IDbConnection dbConnection=Connection)
{
var data=dbConnection.Query(@“选择替换(将NVARCHAR(10),fystart,6),”,“,-”)作为fystart,
替换(将(NVARCHAR(10),fyend,6),“,”-”)从fydates转换为fyend,其中yearlabel=@yearlabel“,
新的{yearlabel=yearlabel}).Single();
List DataQuery=dbConnection.Query(@“选择V.id,V.voucheno,
当V.vouchertype='P'然后'Paid'或者'Receipt'以vouchertype结尾时,
替换(将(NVARCHAR(10),V.dated,6),“,”-”)为日期,V.subno,V.amount,合并(V.syscreated),)为syscreated,V.bankcode,
合并(V.cheqno“”)为cheqno,V.Cheqdate,V.posted,V.currency,A.id为accountsid,A.achead,A.shortname,
D.id作为部门id,D.divname,D.divncode,L.id作为lockstatusid,L.name来自凭证V
在V.bankcode=A.mainac上左连接帐户A
在V.divisionid=D.divncode上左连接divisionmst D
左连接锁定状态L在V.posted=L.Type上
其中(V.voucheno+V.Subno+V.cheqno+A.achead+LEFT(yearvoucheno,3)像@word和
D.divncode,如@division code)和(日期介于@fystart和@fyend之间,或日期为@49年3月31日)
按V.id描述偏移量订购@pageno*25行仅取下25行“,
(凭证、账户、部门、锁定状态)=>
{
凭证.账户=账户;
凭证.分割=分割;
凭证.锁定状态=锁定状态;
退货凭证;
},
新{word=word,fystart=data.fystart,fyend=data.fyend,DivisionCode=DivisionCode,pageno=pageno-1},
splitOn:“accountsid,divisionid,lockstatusid”).ToList();
返回数据查询;
}

}
只需添加虚拟列,以帮助Dapper知道在哪里拆分。请注意,如果伪列为null,则关联的对象将为null。还要注意,伪列不需要存在于目标对象上

select
--first object
1 AS Id,
(1+1) AS APropertyAssociatedToYourFirstObject,
(1+1) AS ADifferentPropertyAssociatedToYourFirstObject,

--second object (assuming you are splitting on Id)
1 AS Id,
(1+1) AS APropertyAssociatedToYourSecondObject,
(1+1) AS ADifferentPropertyAssociatedToYourSecondObject
from YourTable
而且,像这样排列可以节省大量的时间