Int list returned by LINQ query

I have one table with ID and other attributes.

How can I get a list of int ids by LINQ query in this table?

0


a source to share


2 answers


Use the Select method to project the result in a different format:

var myList = myTable.Select(t => t.ID).ToList();

      

This should do it, note that you can also use a syntax similar to SQL:



var myList = (from t in myTable
             select t.ID).ToList();

      

EDIT:

Also note that this is C # syntax, if you need other syntax you need to clarify which language you are using.

+7


a source


Try



var list = from b 
           in MyDataContext.Table
           select b.ID

      

+1


a source







All Articles