Querying into a complex object with sqlkata
My code:
var compiler = new SqlServerCompiler();
var db = new QueryFactory(connection, compiler);
var person = db.Query("Person")
.Select("Person.Id", "Person.Name", "Contact.Id", "Contact.FoneNumber")
.Join("Contact", "Person.Id", "Contact.PersonId")
.Where("Person.Id", 1)
.FirstOrDefault<Person>();
As you have wrote before, use the Join Method to join with the "Contact" table,
var row = db.Query("Person")
.Select(
"Person.Id",
"Person.Name",
"Contact.Id as ContactId",
"Contact.FoneNumber as FoneNumber"
)
.Join("Contact", "Person.Id", "Contact.PersonId")
.Where("Person.Id", 1)
.FirstOrDefault();