Could you help me to translate this Linq query to extension methods:
var query = from person in people
join pet in pets on person equals pet.Owner into gj
from subpet in gj.DefaultIfEmpty()
select new { person.FirstName, PetName = (subpet == null ? String.Empty : subpet.Name) };
The query come from MSDN page about Left outer join.
I already did this:
var result = people.join(pets, x, y => y.Owner, (x, y) => {
x.FirstName,
PetName = y == null ? String.Empty : y.Name
}).ToList();
But I don't know what to do with the DefaultIfEmpty()
?
Adding the DefaultIfEmpty()
as explained on other solutions result in CS0746 Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.