How to do Select All(*) in linq to sql

chobo2 picture chobo2 · Oct 18, 2009 · Viewed 245k times · Source

How do you select all rows when doing linq to sql?

Select * From TableA

In both query syntax and method syntax please.

Answer

Simon Buchan picture Simon Buchan · Oct 18, 2009
from row in TableA select row

Or just:

TableA

In method syntax, with other operators:

TableA.Where(row => row.IsInteresting) // no .Select(), returns the whole row.

Essentially, you already are selecting all columns, the select then transforms that to the columns you care about, so you can even do things like:

from user in Users select user.LastName+", "+user.FirstName