Me pregunto si hay implicaciones de rendimiento de varias sentencias .Where(). Por ejemplo, yo podría escribir:¿Hay varias sentencias .Where() en LINQ, un problema de rendimiento?
var contracts = Context.Contract
.Where(
c1 =>
c1.EmployeeId == employeeId
)
.Where(
c1 =>
!Context.Contract.Any(
c2 =>
c2.EmployeeId == employeeId
&& c1.StoreId == c2.StoreId
&& SqlFunctions.DateDiff("day", c2.TerminationDate.Value, c1.DateOfHire.Value) == 1
)
)
.Where(
c1 =>
!Context.EmployeeTask.Any(
t =>
t.ContractId == c1.Id
)
);
O, alternativamente, podría combinar todos ellos en la cláusula where(), así:
var contracts = Context.Contract
.Where(
c1 =>
c1.EmployeeId == employeeId
&& !Context.Contract.Any(
c2 =>
c2.EmployeeId == employeeId
&& c1.StoreId == c2.StoreId
&& SqlFunctions.DateDiff("day", c2.TerminationDate.Value, c1.DateOfHire.Value) == 1
)
&& !Context.Employee_Task.Any(
t =>
t.ContractId == c1.Id
)
);
¿La cadena de Donde() cláusulas perjudicar el rendimiento o son ¿equivalentes?
creo LINQ compila tanto a una expresión similar, independientemente de cómo se construye (siempre y cuando no llame a ToList() o al tipo entre 'Where's' – sinelaw