Reputation: 73
I do not know how to ask this question. So I will just give an example.
Code:
var db = new dbContext();
var dlo = new DataLoadOptions()
dlo.LoadWith<Order>(x => x.Company);
db.LoadOptions = dlo;
var compIds = prms.companies.Select(x => x.Id).ToArray();
as I understand with above code I load Company from Order table and then getting companies by their ID's. Is it same as
var compIds = (from it in context.GetTable<Order>()
select it.Company.Id).ToArray();
? Or am I totally confusing two different concepts?
Upvotes: 0
Views: 553
Reputation: 3503
I think you are confused about three things:
context.GetTable<Order>()
is the same as context.Orders
(assuming everything is configured correctly.
The queries you've provided as examples are not equivalent; they ask two different questions. The first is asking "Give me all the Company IDs". The DataLoadOptions
won't even be used. The second is asking Give me every Order's Company ID. You will get duplicates.
DataLoadOptions
is generally used for eager loading of related object instances, not joining.
I think what you are really looking for is:
var uniqueCompanyIDsThatHaveAtLeastOneOrder = db.Orders.Select(o => o.Company.Id).Distinct();
Upvotes: 2