问题描述
我想了解LINQ的某些性能含义,从这个免费的电子书由展鹏的
I am trying to understand some performance implication of Linq from this free ebook by RedGateftp://support.red-gate.com/ebooks/under-the-hood-of-net-memory-management-part1.pdf
在这本书157-158页,他们创造了下面的例子。
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();
}
然后,他们再分解的LAMDA EX pression部分进入下面的函数。
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();
}
根据什么我研究至今,其无法运行此LINQ查询作为LINQ将不能够识别该方法,不能被转化为一个商店前pression。我不知道这个例子是错误的,根本无法运行,或者如果我只是有很难让我听到周围如何模拟这个问题?
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?
推荐答案
您是正确的,这将不能够通过LINQ到实体它显示的方式来调用。
You are correct, this would not be able to be called by LINQ-to-Entities the way it's displayed.
它可以在使用的唯一方法LINQ到实体是:
The only way it could be used in LINQ-to-Entities is to:
- 创建服务器端功能的等价物。
- 映射函数模型适当,以便它正确地转换了电话。
- Create the equivalent of the function on the server side.
- Map the function in the model appropriately so that it translates the call correctly.
这篇关于是否有可能调用其中中调用命名的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!