Is there a better way to handle multiple join statements in a linq query? I am rewriting a VB.NET app into C#. I won't subject you to the original code. I am mainly looking for a better way to handle all the join statements that are being done. I am dealing with a legacy database that I cannot currently change the structure of. (Though I am making my arguments for it)

I am wondering if there is a better / cleaner way to handle multiple join statements. I am using DB first EF 6.1 so I have more options than was originally available. Here is the original Linq query converted to C#:

(from myObject in _context.MyObjects
join myObjectType in _context.MyObjectTypes on myObject.CRTKey equals myObjectType.CRTKey
join myObjectsSchedule in _context.MyObjectSchedule on myObject.CRS_Key equals myObjectsSchedule.CRS_Key
join myObjectGroup in _context.MyObjectGroups on myObject.ReportKey equals myObjectGroup.ReportKey
where myObjectGroup.ReportGroupNameKey == groupNameKey
select myObject).Distinct();


This particular example only has three joins I have a few blocks of code that have in  excess of 6 join statements. Is there a better way to handle all the join statements?
I'm not sure what you mean by a 'cleaner way'. The syntax you're using is known as query syntax and is by far the best for readability when you have multiple joins.

If you use method syntax to express the same query you'll quickly see what I mean.

However, if you use method syntax you'll be able to break those joins up using different methods.

For example:

IGrouping&lt;Results&gt; AddJoin(IQueryable&lt;Stuff&gt; query) {

    if (business_rule) {
        return query.Join(inner =&gt; inner.Key, outer =&gt; inner.Key == outer.Key);
    }

    return query;
}


In this way you can reuse parts of your join and construct them dynamically.

Hope this helps.