Reputation: 1978
Which query is optimized :
db.news.Select(c => new { c.Title, c.Date, c.ID })
.SingleOrDefault(c => c.ID == 1);
or
db.news.Where(c => c.ID == 1)
.Select(c => new { c.Title, c.Date })
.SingleOrDefault();
I want this query:
select title, date
where id = 1
in global which one is better where
before select
, or where
after select
?
Upvotes: 1
Views: 962
Reputation: 76
Generally, Where
before Select
(Where
first approach) is more performant, since it filters your result set first, and then executes Select
for filtered values only.
Upvotes: -1