Entity from datatable

c# datatable entity-framework

Question

Is it feasible to add data from a DataTable to an entity?

1
6
3/18/2011 5:01:49 PM

Accepted Answer

I'm not sure if this is precisely what you're looking for, but it should work. You can project the row onto a new object using the .AsEnumerable() extension function.

var products = productTable.AsEnumerable().Select(row => new Product 
{
    ProductID = row.Field<int>("ProductID"),
    Name = row.Field<string>("Name"),
    CreatedDate = row.Field<DateTime>("CreatedDate")
});

I believe that the.Field<T>() If the type of the column has not been specified, you will need to do the type conversion manually since procedure does not perform any type conversions.

10
3/18/2011 5:30:38 PM

Popular Answer

I think you're searching for this: DataTable to Entity Conversion.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow