Sunday, March 11, 2012

DLINQ to DataTable ?

Is there a built in way of converting a LINQ qurey result into a DataTable or DataView ?

The LINQ query result is a collection of strongly typed objects. There is no built-in method to do what you want,although it is possible.

|||

I know it is possibe to do this via reflection, however it could be problematic when using anonymous types.

Anyway I was looking for something built-in and I guess there is none which is a shame. Beta versions of DLINQ did have a built in mechanism.

|||

Sorry, I spoke way too soon:http://blogs.msdn.com/erickt/archive/2007/10/24/linq-to-dataset-data-binding-linqdataview-restriction-joins.aspx

AsDataView() would appear to be what you are after.

|||

AsDataView() is not a part of the release version. From what I've read so far it was available in pervious Beta versions. It is only avaiable as a DataTable extension method and it can be used with Linq to DataSet andnot with Linq to SQL.

No comments:

Post a Comment