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.
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.
精彩评论