tags:

views:

39

answers:

2

I have one table having ID and other attributes.

How can I get list of int of IDs by LINQ query on that table?

+1  A: 

Try

var list = from b 
           in MyDataContext.Table
           select b.ID
Eoin Campbell
This will return IEnumberable<int>, not List<int> - although theres a good chance that the question holder doesn't care.
kastermester
+1  A: 

Use the Select method to project your result into a different format:

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

That should do it, note you can also use the more SQL-like syntax:

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

EDIT:

Also note, this is C# syntax, if you want a different syntax you need to clarify which language you're using.

kastermester