Thursday, 22 August 2013

How to Write Linq for C# ; Differences in Linq Queries

How to Write Linq for C# ; Differences in Linq Queries

If
from lang in Languages
from title in lang.Titles
where lang.name == "Arabic" && title.Type=="Movie"
Select new {title.Name, title.ReleaseYear}
is the same as
Languages
.Where(l=>l.Name == "Arabic")
.SelectMany(l=>l.Titles)
.Where(t=>t.Type=="Movie")
.Select(t=>new{
t.Name, t.ReleaseYear
})
Is there any difference in the 2 ( Query results are same, i mean backend )
Can you choose either or and consider the rest just "Preference"? - or is
one more versitile?

No comments:

Post a Comment