0

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?

1 Answer 1

2

I think you are confused about three things:

  1. context.GetTable<Order>() is the same as context.Orders (assuming everything is configured correctly.

  2. 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.

  3. 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(); 
Sign up to request clarification or add additional context in comments.

1 Comment

oh yes you are right with dlo not being used. I should have wrote var compIds = db.companies... Thanks for comment. What I was trying to get at was answered by your 1st point.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.