You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes we need to perform a heavy operation in the Where clause to satisfy the predicate and then do the same operation in the Select clause to return the final projection.
For example:
varresults= students
.Where(s => CalculateGrade(s.Marks)=='A').Select(s =>new{ Name = s.Name, Grade = CalculateGrade(s.Marks)});
This is possible with the let keyword when using LINQ syntax:
But with method syntax, it is difficult and we typically end up running the operation multiple times. Once recommendation is to create a projection with the initial object and calculated object and work with that:
varresults= students
.Select(s =>new{ Student = s, Grade = CalculateGrade(s.Marks)}).Where(s => s.Grade =='A').Select(new{ Name = s.Student.Name, Grade = s.Grade });
The SelectWhere method enables this scenario without needing the projection.
The text was updated successfully, but these errors were encountered:
Sometimes we need to perform a heavy operation in the
Where
clause to satisfy the predicate and then do the same operation in theSelect
clause to return the final projection.For example:
This is possible with the
let
keyword when using LINQ syntax:But with method syntax, it is difficult and we typically end up running the operation multiple times. Once recommendation is to create a projection with the initial object and calculated object and work with that:
The
SelectWhere
method enables this scenario without needing the projection.The text was updated successfully, but these errors were encountered: