I cant built a complex object with a query. How I do?
public class Person
{
public long Id { get; set; }
public string Name { get; set; }
public Contact Contact { get; set; }
}
public class Contact
{
public long Id { get; set; }
public string FoneNumber { get; set; }
}
You can use a combination of SqlKata (@amd's answer) and Dapper (@Void Ray's answer):
var query = new SqlKata.Query(...); //compose your sqlkata query as user amd indicated above
var compiler = new PostgresCompiler(); //or mssqlcompiler or whatever
var compiled = compiler.Compile(query);
var sql = compiled.Sql;
var parameters = new DynamicParameters(compiled.NamedBindings);
var result = await db.QueryAsync<Person, Contact,Person>(sql,(p,c)=>{p.Contact = c; return p;},parameters);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With