Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linq-to-sql

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

Select * From TableA 

In both query syntax and method syntax please.

like image 792
chobo2 Avatar asked Oct 18 '09 20:10

chobo2


People also ask

How do I select a query in LINQ?

LINQ query syntax always ends with a Select or Group clause. The Select clause is used to shape the data. You can select the whole object as it is or only some properties of it. In the above example, we selected the each resulted string elements.

How use all in LINQ C#?

The Linq All Operator in C# is used to check whether all the elements of a data source satisfy a given condition or not. If all the elements satisfy the condition, then it returns true else return false. There is no overloaded version is available for the All method.

How does select work in LINQ?

Select is used to project individual element from List, in your case each customer from customerList . As Customer class contains property called Salary of type long, Select predicate will create new form of object which will contain only value of Salary property from Customer class.

What is select in LINQ C#?

The Select() method invokes the provided selector delegate on each element of the source IEnumerable<T> sequence, and returns a new result IEnumerable<U> sequence containing the output of each invocation.


1 Answers

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 
like image 198
Simon Buchan Avatar answered Oct 07 '22 20:10

Simon Buchan