+2  A: 

You can consider LINQ in this case.

var list = (from dr in dt.AsEnumerable()
           select new Property { .... }).ToList();

Creates the List as result.

Edit : Made the first sentence mild.

abhishek
Yaah... Sorry, I meant to say LINQ could be a choice in this. :)
abhishek
What do the 3 dots symbolize? Is it an anonymous type and I have to put in every field? Could you flesh this out> Thanks!
Sam Gentile
Also, what if it's a DataSet?
Sam Gentile
@Sam Gentile ~ DataSet is a collection of DataTable with some extra information. You can either `foreach (DataTable dt in ds)` or you can specify each by index `ds.Tables[i]`
drachenstern
@Sam, yes you need to replace the 3 dots with the Property Setters like new Property { Id=dr[0].ToString(), Chain = dr[1].ToString()...}If it is a dataset, you will probably have enumeration of tables. Do you mean you need to put contents of each tables in the same list ?
abhishek
Yes, I may need to put contents of each table in the same list
Sam Gentile
Is it dr in { Id=dr[0].ToString(), Chain = dr[1].ToString()...} or ItemArray[0]. Doesn't ItemArray[i] have the value?
Sam Gentile
A: 

Although this is in VB, you may be able to convert it to C# and use it:

How to convert dataset or dbreader to List(of T) or BindingList(Of T) using mapping

http://prglog.blogspot.com/2009/10/how-to-convert-listof-t-or.html

It looks like it uses reflection and will work with any type.

John Boker
A: 

You could also use the LINQ Select() method

DataTable dt = new DataTable
var list = dt.Rows.Select(row => new Propert
{
SomeProperty = row["columnName"],//etc...
}).ToList();
EJC
seem to be having a little trouble with the code viewer today :-P
EJC
What is EnumerableDataRowList? Is it List<Property> in my case or something defined by the framework?
Sam Gentile
my apologies, that's a custom class we use. You should be able to do the same thing with the by just putting the select on the dt.Rows, I'll fix my example in a sec
EJC
I found your custom class here on Code Project http://www.codeproject.com/KB/linq/LINQGroupByMultipleColumn.aspx?display=Print
Sam Gentile
Guess it's not so custom after all :)
EJC
A: 

Another example:

I wrote this article a few months ago:

http://www.codeproject.com/KB/linq/FromDataTable2GenericList.aspx

Hope it helps!

ssanga
A: 

Just a side note. I've gone down this path before and have found that most of the time I didn't need some sort of entity class wrapper around the datatable. Instead, the normal rows/columns access of the datatable itself was just fine. It saved processing time and memory consumption by just passing the table around.

Typically speaking if I'm pulling the data from a proc for display, I leave it in a table. However, if I have a class which includes additional functionality beyond just holding data, then I might convert the datatable into a list/collection of objects.

On the flip side if data is coming back from the browser, then I'll populate an object whose class definition has all of the associated validation tied in prior to storing in the database.

The point is, unless the entity class is going to give you something you don't already have then I wouldn't bother.

Chris Lively