I’m using EF 4.
I have an IEnumerable<Type01> where each of the items (of Type01) has an IEnumerable<Type02>.
This can explain:
Type01 objType01 = ...;
IEnumerable<Type02> en = objType01.allObjType02;
I need to do (using LINQ) a select that gives me an IEnumerable<Type01> as result, but the “record count” must be the same of the sum of “record count” of all Type02 items.
For example. For this list:
myItem01a
myItem02a
myItem02b
myItem01b
myItem02c
myItem02d
myItem02e
The select return must be:
myItem01a
myItem01a
myItem01b
myItem01b
myItem01b
I know how to do this by using old school SQL (JOIN clause). But I’m fairly new to LINQ expressions.
How could it be done?
Cheat. Use
SelectMany(or the equivalent multiplefroms) to iterate over allType02s, but only yield aType01each time round:Now
repeatedType01sis anIEnumerable<Type01>with the cardinalities you want.