How to achieve this below datatable to a generic list conversion ?
I am trying this:
List<Emp> lstEmp= new List<Emp>(from prod in MyDatatable.AsEnumerable<Emp>() select prod);
How to achieve this below datatable to a generic list conversion ?
I am trying this:
List<Emp> lstEmp= new List<Emp>(from prod in MyDatatable.AsEnumerable<Emp>() select prod);
var empList = MyDatatable.AsEnumerable().Select( row =>
new Emp
{
Name= row.Field<string>("Name") // set the properties accordingly
}).ToList();
try this,
List<Emp> target = dt.AsEnumerable()
.Select(row => new Emp
{
Name = row.Field<string>("Name")
}).ToList();