LINQ to Entities 无法识别方法

发布于 2024-10-28 04:31:48 字数 1989 浏览 1 评论 0原文

我有一个很长的 Linq To Entities 查询:-

reports = db.CallProfileDailies
    .Join(db.ReportDailyTotals, 
          cpd => cpd.Date, 
          rdt => rdt.Date, 
          (cpd, rdt) => new { cpd = cpd, rdt = rdt })
    .Where(a => a.cpd.Skill == a.rdt.Skill)
    .Join(db.SummaryIntervalTotals, 
          a => a.rdt.Date, 
          sit => sit.Date,
          (a, sit) => new { cpd = a.cpd, rdt = a.rdt, sit = sit })
    .Where(a => a.rdt.Skill == a.sit.Skill)
    .Select((a, i) => new ReportModel
    {
        AverageAbandonDelay = a.sit.AvgAbanTime,
        AverageAfterCallWorkTime = a.sit.AvgAcwTime,
        AverageHandleTime = (a.sit.AvgAcwTime + a.sit.AvgAcdTime),
        AverageSpeedOfAnswer = a.sit.AvgSpeedAns,
        AverageTalkTime = a.sit.AvgAcdTime,
        CallsAnswered = a.sit.AcdCalls,
        Date = a.sit.Date.ToString(),
        MaximumDelay = a.sit.MaxDelay,
        PercentageAbandon = (a.sit.AbanCalls / (a.sit.AcdCalls + a.sit.AbanCalls)),
        TotalCallsAbandon = a.sit.AbanCalls,
        TotalCallsOffered = (a.sit.AcdCalls + a.sit.AbanCalls),
        TotalHandleTime = (a.rdt.HoldTime + a.rdt.AcdTime + a.rdt.AcwTime)
    }).Take(5).ToList();

我在运行时收到以下错误:-

LINQ to Entities 无法识别 方法 'System.Linq.IQueryable`1[ExpediaReports.Models.ReportModel] Select[<>f_AnonymousType1`3,ReportModel](System.Linq.IQueryable`1[<>f_AnonymousType1`3[ExpediaReports.CallProfileDaily,ExpediaReports.ReportDailyTotal,ExpediaReports.SummaryIntervalTotal] ], System.Linq.Expressions.Expression`1[System.Func`3[<>f__AnonymousType1`3[ExpediaReports.CallProfileDaily,ExpediaReports.ReportDailyTotal,ExpediaReports.SummaryIntervalTotal],System.Int32,ExpediaReports.Models.ReportModel]])' 方法,并且该方法不能 翻译成商店表达式。

我只是想了解这个错误是什么意思。我什至无法读取它(Linq To Entities)无法识别的方法。

如何读取此错误并识别无法识别的方法,以便我可以相应地更改我的查询?

这些字符在这里意味着什么:` <> ' ETC。

I have a long Linq To Entities query:-

reports = db.CallProfileDailies
    .Join(db.ReportDailyTotals, 
          cpd => cpd.Date, 
          rdt => rdt.Date, 
          (cpd, rdt) => new { cpd = cpd, rdt = rdt })
    .Where(a => a.cpd.Skill == a.rdt.Skill)
    .Join(db.SummaryIntervalTotals, 
          a => a.rdt.Date, 
          sit => sit.Date,
          (a, sit) => new { cpd = a.cpd, rdt = a.rdt, sit = sit })
    .Where(a => a.rdt.Skill == a.sit.Skill)
    .Select((a, i) => new ReportModel
    {
        AverageAbandonDelay = a.sit.AvgAbanTime,
        AverageAfterCallWorkTime = a.sit.AvgAcwTime,
        AverageHandleTime = (a.sit.AvgAcwTime + a.sit.AvgAcdTime),
        AverageSpeedOfAnswer = a.sit.AvgSpeedAns,
        AverageTalkTime = a.sit.AvgAcdTime,
        CallsAnswered = a.sit.AcdCalls,
        Date = a.sit.Date.ToString(),
        MaximumDelay = a.sit.MaxDelay,
        PercentageAbandon = (a.sit.AbanCalls / (a.sit.AcdCalls + a.sit.AbanCalls)),
        TotalCallsAbandon = a.sit.AbanCalls,
        TotalCallsOffered = (a.sit.AcdCalls + a.sit.AbanCalls),
        TotalHandleTime = (a.rdt.HoldTime + a.rdt.AcdTime + a.rdt.AcwTime)
    }).Take(5).ToList();

I am getting the following error at runtime:-

LINQ to Entities does not recognize
the method
'System.Linq.IQueryable`1[ExpediaReports.Models.ReportModel]
Select[<>f_AnonymousType1`3,ReportModel](System.Linq.IQueryable`1[<>f_AnonymousType1`3[ExpediaReports.CallProfileDaily,ExpediaReports.ReportDailyTotal,ExpediaReports.SummaryIntervalTotal]],
System.Linq.Expressions.Expression`1[System.Func`3[<>f__AnonymousType1`3[ExpediaReports.CallProfileDaily,ExpediaReports.ReportDailyTotal,ExpediaReports.SummaryIntervalTotal],System.Int32,ExpediaReports.Models.ReportModel]])'
method, and this method cannot be
translated into a store expression.

I just want to understand what does this error mean. I am not even able to read which method it (Linq To Entities) is not able to recognize.

How to read this error and identify the unrecognized method so that I can change my query accordingly ?

What does these characters mean here : ` <> ' etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

究竟谁懂我的在乎 2024-11-04 04:31:48

“此方法无法转换为存储表达式”意味着 Linq to Entities 无法将您的查询转换为 SQL。

当您的 .Select() 函数中的某些内容试图以无法直接转换为 SQL 的方式操作结果时,例如当您运行函数时,通常会发生这种情况。我敢打赌“a.sit.Date.ToString()”行导致了这个问题。只需在调用 .ToList() 后返回日期并对其进行格式化,我敢打赌问题就会消失。

这可能会令人沮丧——Linq to SQL 在运行这样的查询方面要好得多,因为您的 .Select() 函数中有复杂的函数。请记住,Linq to Entities 转换为 SQL 的功能非常有限。

"this method cannot be translated into a store expression" means that Linq to Entities can't translate your query to SQL.

This often happens when you have something in your .Select() function that tries to manipulate the results in a way that can't be directly translated to SQL, such as when you run a function. I'd bet that the "a.sit.Date.ToString()" line is causing the problem. Just return the date and format it after you've called .ToList() and I'll bet the problem will go away.

It can be frustrating -- Linq to SQL was a lot better at running queries like this where you had complex functions in your .Select() function. Keep in mind that Linq to Entities is very limited on the functions it will translate over to SQL.

铃予 2024-11-04 04:31:48

使用 ToString 确实不起作用,但这里的问题是 .Select((a, i) => 不支持此版本的 Select Linq-to-entities 说的。

Using ToString really doesn't work but problem here was .Select((a, i) => This version of Select is not supported by Linq-to-entities. Exception says it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文