In the second fragment, the logic is translated into a lambda expression, which is then compiled into an expression tree ... two queries:
_context.Customers
.Where(customer => TrimAndCompare(customer.CustomerID, customerID);
vs
_context.Customers
.Where(customer => customer.CustomerID.Trim() == customerID.Trim());
LINQ to SQL , , Trim . , , .
, , , :
Expression<Func<Customer, bool>> CustomerIdMatches(string customerID)
{
return customer => customer.CustomerID.Trim() == customerID.Trim()
}
:
from customer in context.Customers.Where(CustomerIdMatches(customerID))
... rest of query here
Where.
. , ... , .
:
var query = context.Customers
.Where(TrimAndCompare(customer => customer.CustomerID,
customer => customerID));
: (