I have 3 entities :
class Foo {
public Guid? BarId { get; set; } //Has optional bar
[NotMapped]
public boolean? HasXyzzy { get; set; }
}
class Bar {
...
}
class Xyzzy {
public Guid BarId { get; set; } //Always has Bar
}
I want to retrieve some Foo
from database and fill their HasXyzzy
property. I'm using LINQ to entities extension methods.
I was thinking of something like this :
var xyzzys = xyzzyRepository.GetAll(); //IQueryable
var foos = fooRepository.GetAll()
.Where() //Some condition
.SelectMany(
foo => xyzzys.Where(xyzzy => xyzzy.BarId == foo.BarId).DefaultIfEmpty(),
(foo, xyzzy) => new Foo {
BarId = foo.BarId,
HasXyzzy = xyzzy != null
});
But this is quite tedious since my Foo class has a lot of properties.
What would be the correct way to do this ?