querybuilder
querybuilder copied to clipboard
How to use join with like automapping?
When i use a join (which works as i can see when i look at the non generic function return value) with the generic overload GetAsync<Entity>(), then the relational properties are still null. Am i missing something or isn't it possible with sqlkata?
@robbelroot could you provide a code example?
Sure, but it's just a trivial join, nothing special:
_db.Query($"Jobs") .Join($"Customers", "Jobs.customer_id", "Customers..id")
And the Job Class:
public class Job : Entity<long> { public Customer Customer { get; set; } public Job() { } }
No, it doesn't work this way, the joined columns will be returned on the same level as the original table record. For example, the result class should be similar to:
public class JobWithCustomer {
public int JobId;
public string Position;
public int CustomerId;
public string CustomerName;
}
for a query like this one
db.Query("Jobs").Join("Customers", ...).Select("Jobs.{JobId, Position}", "Customers.{CustomerId, CustomerName}");
You can use the .Include
and .IncludeMany
to include related properties, but the only limitation, for now, is that this will work only on the non-typed overload of Get
and GetAsync
.
_db.Query("job").Include("customer", q => q.From("customer"))
Gives me the error:
Lambda expression cannot be converted to type Query because it's no delegate type.
Got version 2.2.0 of your Package.
EDIT:
I just saw that the current version seems to use just a Query
as second parameter, so i changed q => q.Query("customer")
to just _db.Query("customer")