FM250
FM250

Reputation: 1

Linq to Entities: cannot be translated into a store expression

I am trying to execute this query, but I am getting an error: cannot be translated into a store expression.

If I can't do it this way how can I implement it? I am using C#.

I am trying to display training records if the date taken is not this year. Any suggestion is highly appreciated.

tr =  from l in t.Trainees
      where !db.UserTrainings.Any(ut => ut.Trainees.TraineeId == l.TraineeId &&
                                        ut.Passed == true &&
                                        ut.DateTaken >= l.DateEnded.Value.AddYears(-1)) 
      ...... rest of the query.

Upvotes: 0

Views: 802

Answers (1)

Stephen Cleary
Stephen Cleary

Reputation: 456437

I have not had a chance to use EntityFunctions before, but I believe that it could be used to solve your problem.

Try replacing l.DateEnded.Value.AddYears(-1) with EntityFunctions.AddYears(l.DateEnded, -1). The method is documented on MSDN.

Upvotes: 1

Related Questions