LINQ Lambda-Expression Diff

It's probably very simple, I'm just on the fence today. The Lambda version works as expected the Expression version does not. Do you see where the difference is? Works:
var groupedOccurences = occurences
.SelectMany(static occurence => occurence.MailAddress.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(addr => new
{
MailAddress = addr.Trim(),
occurence.DatabasePath,
occurence.MaskName
}))
.GroupBy(static occurence => occurence);
var groupedOccurences = occurences
.SelectMany(static occurence => occurence.MailAddress.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(addr => new
{
MailAddress = addr.Trim(),
occurence.DatabasePath,
occurence.MaskName
}))
.GroupBy(static occurence => occurence);
Does not work (different results):
var groupedOccurences = from occurence in occurences
from address in occurence.MailAddress.Split(',', StringSplitOptions.RemoveEmptyEntries)
group new {
MailAddress = address.Trim(),
occurence.DatabasePath,
occurence.MaskName
} by occurence into grp
select grp;
var groupedOccurences = from occurence in occurences
from address in occurence.MailAddress.Split(',', StringSplitOptions.RemoveEmptyEntries)
group new {
MailAddress = address.Trim(),
occurence.DatabasePath,
occurence.MaskName
} by occurence into grp
select grp;
3 Replies
ero
ero2y ago
Why would you use the query expression in the first place...? Well anyway Doesn't your IDE offer to convert the call chain to a query expression on Ctrl + .?
Robin Lindner
Robin Lindner2y ago
readability? why wouldn't you use it? nope
ero
ero2y ago
May god have mercy on your soul if you think that's more readable