Howard Tucker
Howard Tucker

Reputation: 438

Linq causes syntax error with Top (1)

I have an EF context using linq that is being executed on multiple sql servers of varying types. What I have found is that linq is causing a syntax error on a sql server 2000 box because the linq translation for .FirstOrDefault() is being translated into sql that uses SELECT TOP (1) instead of SELECT TOP 1 and it would seem that the parenthesis are causing this syntax error as they are not supported in this context in sql server 2000.

Is it possible to force linq to use SELECT TOP 1 instead of SELECT TOP (1) ?

Upvotes: 3

Views: 632

Answers (1)

IT ppl
IT ppl

Reputation: 2647

you can use ToList().Take(1) method after ordering.

Upvotes: 3

Related Questions