I have this working sample query using dapper ( in reality I'm using a real table) :
async void Main()
{
var sql = @"SELECT PersonId = 1,
FirstName = 'john',
LastName = 'Lennon'";
using (var conn = new SqlConnection(@"Data Source=....;Initial Catalog=W...."))
{
var person = await conn.QueryAsync<Person>(sql);
person.Dump();
}
}
public class Person
{
public int PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
Result :
So mapping is working as expected. But sometimes I have queries which returns another value like :
SELECT PersonId = 1,
FirstName = 'john',
LastName = 'Lennon' ,
cnt=(SELECT COUNT(1) FROM INFORMATION_SCHEMA.COLUMNS) //example
Which is perfectly legal :
Question :
Is it possible to return a Person
object and other non mapped values ( in the same select
)
Something like :
await conn.QueryAsync<Person,int>(sql)
A real example :
SELECT [AddressId]
,[PersonName]
,[Street]
,[Address_2]
,[House] ,
cnt=(COUNT(1) OVER (PARTITION BY house) )
FROM [WebERP].[dbo].[App_Address]
So I return an Address
object with count which regards to the same table and I don't want another select.