I have the following SQL statement to get data from multiple tables inside my SQL Server database:
SELECT max(ad.ORG_NAME) AS "Account", wo.WORKORDERID AS "Request ID", max(aau.FIRST_NAME) AS "Requester", max(aci.emailid) "Email ID",max(wo.TITLE) AS "Request Title", max(ti.FIRST_NAME) AS "Technician", longtodate(max(srm.Responsetime)) AS "Survey responded Time", max(srcmt.COMMENTTEXT) AS "Comments",max(srm.result) "Over All Satisfaction Level" FROM SurveyResponseRequestMapping srrm
INNER JOIN Survey_Response_Main srm ON srrm.RESPONSEID=srm.RESPONSEID
INNER JOIN Survey_Response_Answer sra ON srm.RESPONSEID=sra.RESPONSEID
LEFT JOIN Survey_Response_Comment srcmt ON srm.RESPONSEID=srcmt.RESPONSEID
LEFT JOIN WorkOrder wo ON srrm.WORKORDERID=wo.WORKORDERID
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID
LEFT JOIN SDUser td ON wos.OWNERID=td.USERID
LEFT JOIN AaaUser ti ON td.USERID=ti.USER_ID
LEFT JOIN SDUser sdu ON wo.REQUESTERID=sdu.USERID
LEFT JOIN AaaUser aau ON sdu.USERID=aau.USER_ID
INNER JOIN AccountSiteMapping asm ON wo.siteid=asm.siteid
INNER JOIN AccountDefinition ad ON asm.accountid=ad.org_id
left join aaausercontactinfo auci on auci.user_id = sdu.userid
left join aaacontactinfo aci on aci.contactinfo_id = auci.contactinfo_id
where srm.RESPONSETIME>=DATETOLONG('2021-03-22 00:00:00') and srm.RESPONSETIME<=DATETOLONG('2021-03-31 23:59:59')
GROUP BY wo.WORKORDERID order by 7
My question is if can I run this raw SQL statement inside my .NET core console application and map the returned columns into C# variables?
Thanks
You can use Dapper for run Raw SQL code and set value to class
var data = await connection.QueryAsync<YourClass>(sql, parameters);
Note: you can create new class then create property like your query must some (Name and Datatype)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.