Звучит так, как вы хотите Декартово произведение из всех Car
с со всеми Color
с как ValueTuple<Car,Color>
.
Для создания декартового произведения из любых двух списковFoo
и Bar
в Linq делают это:
// (This approach uses the extension method syntax instead of the C# keywords `from`, `join`, etc)
// Type names have been added to lambda functions to make it obvious what the values are.
IEnumerable<Foo> fooValues = ...
IEnumerable<Bar> barValues = ...
IEnumerable< ( Foo, Bar ) > cartesianProduct = fooValues
.SelectMany( Foo foo => barValues, ( Foo foo, Bar bar ) => /* the following syntax creates a new ValueTuple in C# 7: */ ( foo, bar ) );
// or more succinctly (removing unnecessary type names):
var cartesianProduct = fooValues
.SelectMany( foo => barValues, ( foo, bar ) => ( foo, bar ) );
В вашем случае:
List<Car> cars = _ctx.Objekte
.OrderBy( c => c.Nummer )
.ToList();
List<Color> colors = // (you haven't shown how you get a List<Color>)
IEnumerable<(Car,Color)> cartesianProduct = cars
.SelectMany( c => colors, ( car, color ) => ( car, color ) );
Затем вы можете итерировать по cartesianProduct
напрямую - но я не думаю,вам нужно, потому что ваш CarsRow
объект идентичен (Car,Color)
ValueTuple
объекту, но если вы хотите выполнить дополнительную обработку, вы можете сделать это:
foreach( (Car car, Color color) in cartesianProduct )
{
// do stuff with `car` and `color`
}