0

Hopefully, this question has an easy answer and it is simply escaping me at the moment.

If I have a query like...

from p in context.Parents select p; 

...and I also have the query...

from p in context.Parent.Include("Children") select p; 

...what is the best way to conditionally include the call to the Include method? By this, I would like to use the same query to handle both conditions (with, say, a boolean flag like includeChildren). It seems like I have done this in the past using the method syntax but the LINQ syntax is a bit more friendly with complex queries that include joins (in my opinion).

2
  • I worked with this a bit longer. What I discovered is that if the call to the Include method is made before the actual query is constructed, the query will ignore the Include part once a join in the query is added. If I add the Include after the query is built, this appears to work, albeit appearing a bit clunky. Perhaps this is related to the provider I am using (MySQL). Commented Apr 3, 2015 at 13:05
  • As a side note, I really wish this question wouldn't have been marked as a duplicate without asking for additional detail. It was assumed that it was a duplicate but it is not (or at least the information in the other question did not work). As such, I cannot add an answer where the information will be more visible to anyone that has the same issue. Commented Apr 3, 2015 at 13:07

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.