I am new to linq to objects in C#. I have the following query which works adequately. Is there someway to reduce or rewrite this query using joins or something else?
var query =
from container in containers
let items = container.GetItems()
from itemA in items
let tag = CreateTag(itemA)
where IsInteresting(tag)
from itemB in items
let derivedTag = CreateDerivedTag(tag)
where CreateTag(itemB) == derivedTag
select new { first = itemA, second = itemB };
To summarize,
- there are a set of item sequences
for each item sequench
- for each item A that is IsInteresting()
- find an item B in the same sequence that matches based on the criteria derived from the item A
- create a new item containing a reference to matching items A and B
- for each item A that is IsInteresting()
return a collection of all such matching items