I am trying to understand some performance implication of Linq from this free ebook by RedGate ftp://support.red-gate.com/ebooks/under-the-hood-of-net-memory-management-part1.pdf
On page 157-158 in this book, they created following example.
Order[] pastDueAccounts = null;
DateTimedueDate = DateTime.Today.AddDays(-7);
using(varcontext = new Context())
{
pastDueAccounts = context.Accounts.Where(account => account.DueDate < dueDate).ToArray();
}
They then re-factored part of lamda expression into following function.
public bool PastDueAccount(Account account)
{
return account.DueDate < DateTime.Today.AddDays(-7);
}
Finally they used this function as follows.
Order[] pastDueAccounts = null;
using(varcontext = new Context())
{
pastDueAccounts = context.Accounts.Where(account => PastDueAccount(account)).ToArray();
}
Based on what I researched so far, its not possible to run this linq query as LINQ will not be able recognize the method and cannot be translate into a store expression. I wonder if this example is wrong and simply not possible to run or if I am just having hard time getting my heard around on how to simulate this problem?
You are correct, this would not be able to be called by LINQ-to-Entities the way it's displayed.
The only way it could be used in LINQ-to-Entities is to:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With