ispiro
ispiro

Reputation: 27703

Select specific columns from First() row with Linq2sql

I want to use First() in a Linq2sql query, but I don't want the database to return the whole row, just specific columns. Is there a way to do that?

If I use Where() I can then Select() (while it stays an IQueryable), but if I use Where() it will iterate over all rows instead of stopping when it finds a match.

Upvotes: 1

Views: 245

Answers (1)

Angel Q
Angel Q

Reputation: 124

when you use "Where" it does not iterate over all record until you actually execute the query. because thats how linq works, until you actually use the result of the query (convert it to a list, bind to a gridview, etc...) it is not executed so you can add as many conditions as you want and they will combine into a single query.

so where.select.first should work

Upvotes: 1

Related Questions