2

I have a table that has 4 rows whit this role:

Models.tblAssessmentRequest p = new Models.tblAssessmentRequest();
p = biz.Entities.Where(a => a.SuggestionId == SuggestionId).LastOrDefault();

but when I execute my program, I got this error:

LINQ to Entities does not recognize the method 'Models.tblAssessmentRequest LastOrDefaulttblAssessmentRequest' method, and this method cannot be translated into a store expression.

Anyone help me?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Asieh hojatoleslami
  • 3,240
  • 7
  • 31
  • 45

1 Answers1

0

Try this expression to take last.

p = biz.Entities.Where(a => a.SuggestionId == SuggestionId).OrderBy(p => p.SuggestionId).Select(p => p.OrderByDescending(x => x.Id).Take(1).Single());

Hope it helps you

Neeraj Dubey
  • 4,401
  • 8
  • 30
  • 49