LINQ到实体无​​法识别方法 [英] LINQ to Entities does not recognize method

查看:133
本文介绍了LINQ到实体无​​法识别方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很长的LINQ实体查询: -

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到实体不承认   该方法   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.Ex$p$pssions.Ex$p$pssion`1[System.Func`3[<>f__AnonymousType1`3[ExpediaReports.CallProfileDaily,ExpediaReports.ReportDailyTotal,ExpediaReports.SummaryIntervalTotal],System.Int32,ExpediaReports.Models.ReportModel]])'   方法,而这种方法不能   翻译成一家商店前pression。

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.

我只是想了解什么呢这个错误的意思。我甚至不能够读取其方法是(LINQ实体)无法识别。

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 ?

这是什么这些字符的意思是在这里:`&LT;>等。

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

推荐答案

这种方法不能被翻译成店前pression意味着LINQ到实体不能转换您的查询的SQL。

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

这往往当你有东西在你的。选择()函数,试图操纵结果的方式,不能直接转换为SQL,发生在你运行一个函数,如。我打赌,a.sit.Date.ToString()行导致了问题。只是返回的日期和格式化你叫.ToList(后),我敢打赌,这个问题就会迎刃而解。

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.

它可以是令人沮丧 - LINQ到SQL是很多在运行的查询像这样,你在你的。选择()函数有复杂的功能更好。请记住,LINQ到实体是非常有限的功能,它会转化过来的SQL。

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.

这篇关于LINQ到实体无​​法识别方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆