quite easy question about linq

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

I have this linq query below which works as expected but I have one
question.
If I just change the .Select operator to *.Select(eo => new {id = e.id,
optionsCount = eo.optionsCount}));*
Here as you can see I have taken the id from variable e which is employee
insted of eo will the result be the same ?
I'm almost sure it will but I just want to be 100 % sure.


Employee[] employees = Employee.GetEmployeesArray();
EmployeeOptionsEntry[] empOptions =
EmployeeOptionEntry.GetEmployeeOptionEntries();
var employeeOptions = employees
.SelectMany(e => empOptions
.Where(eo => eo.id == e.id)
.Select(eo => new {id = eo.id, optionsCount
= eo.optionsCount}));

foreach (var item in employeeOptions)
Console.WriteLine(item);

//Tony
 
Tony Johansson said:
Hello!

I have this linq query below which works as expected but I have one
question.
If I just change the .Select operator to *.Select(eo => new {id = e.id,
optionsCount = eo.optionsCount}));*
Here as you can see I have taken the id from variable e which is employee
insted of eo will the result be the same ?
I'm almost sure it will but I just want to be 100 % sure.


Employee[] employees = Employee.GetEmployeesArray();
EmployeeOptionsEntry[] empOptions =
EmployeeOptionEntry.GetEmployeeOptionEntries();
var employeeOptions = employees
.SelectMany(e => empOptions
.Where(eo => eo.id == e.id)
.Select(eo => new {id = eo.id,
optionsCount
= eo.optionsCount}));

foreach (var item in employeeOptions)
Console.WriteLine(item);

Assuming that the id is something simple like an int or string then the
answer is yes.

However if the type of the id property is something more complex then it
would depend on how the == operator is implemented by that type.
 
Back
Top