teenup
teenup

Reputation: 7667

LINQ to Entities does not recognize method

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.

Upvotes: 3

Views: 5356

Answers (2)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364249

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.

Upvotes: 1

Dave Markle
Dave Markle

Reputation: 97671

"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.

Upvotes: 10

Related Questions