I have GetClientDocumentRequestResponse response dto. In this I have GetDocumentRequestClientResponse DTO which property name is client and GetDocumentRequestClientResponse DTO which property name is RequestedBy.
Now, when I run the query in Dapper, the values are not populated in client and RequestedBy object which are properties of GetClientDocumentRequestResponse. Other properties of this class do get values.
Here is the GetClientDocumentRequestResponse class:
public sealed class GetClientDocumentRequestResponse
{
public int RequestId { get; set; }
public int ClientId { get; set; }
public int RequestedById { get; set; }
public string DocumentName { get; set; } = string.Empty;
public GetDocumentRequestClientResponse Client { get; set; } = new GetDocumentRequestClientResponse();
public GetDocumentRequestClientResponse RequestedBy { get; set; } = new GetDocumentRequestClientResponse();
}
public class GetDocumentRequestClientResponse
{
public int ClientId { get; set; }
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string CompanyName { get; set; } = string.Empty;
}
Here is how I am running my Dapper queries:
const string sql = $@"SELECT TOP 1
cdr.RequestId,
cdr.ClientId,
cdr.RequestedById,
cdr.DocumentName,
client.ClientId AS Client_ClientId,
client.CompanyName AS Client_CompanyName,
client.FirstName AS Client_FirstName,
client.LastName AS Client_LastName,
requestedBy.ClientId AS RequestedBy_ClientId,
requestedBy.CompanyName AS RequestedBy_CompanyName,
requestedBy.FirstName AS RequestedBy_FirstName,
requestedBy.LastName AS RequestedBy_LastName,
FROM ClientDocumentRequest cdr
LEFT JOIN ClientInfo client ON cdr.ClientId = client.ClientId
LEFT JOIN ClientInfo requestedBy ON cdr.RequestedById = requestedBy.ClientId
WHERE cdr.RequestId = @RequestId
AND cdr.TenantId = @TenantId
;";
var response = (await connection.QueryAsync<GetClientDocumentRequestResponse, GetDocumentRequestClientResponse,
GetDocumentRequestClientResponse, GetClientDocumentRequestResponse>(
sql,
(cdr, client, requestedBy) =>
{
cdr.Client = client;
cdr.RequestedBy = requestedBy;
return cdr;
},
parameters,
splitOn: "Client_ClientId,RequestedBy_ClientId"
)).FirstOrDefault();
When running this query on the database, I am getting values in Client and RequestedBy objects as well.