Is there a way to do the below dynamically so I don't have to repeat myself?
var result = from c in _Entities.Cars
where c.Colour == "White"
select c;
var result = from m in _Entities.Bikes
where m.Colour == "White"
select m;
etc...
as in:
var entities = new List<string> {"Cars", "Bikes"};
foreach (var e in entities)
{
var result = from m in e //pseudo code
where m.Colour == "White"
select m;
}
If Cars and Bikes implement a common interface, say IVehicle, which has the Colour property, you could define a function:
and then
If Cars and Bikes are generated classes from Entity Framework, you can nevertheless make them implement an interface by adding a new source file with a partial definition of the classes with the same name: