ExtJSdeveloper

I am using LINQ to SQL but have a requirement to ship some DataTable objects out to a legacy UI tier. The LINQ api has other collection creation apií»s such as ToArray() and ToDictionary() but I could not find a ToDataSet() or ToDataTable() equivalent.

Have I overlooked something or will I have to code this by hand

Is this Mike Taulty code my best option

http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2007/03/03/9144.aspx



Re: LINQ Project General Looking for ToDataTable()

Fabrice MARGUERIE

A better bet is the code Andrew Conrad from Microsoft provided on his blog. It comes from the old ToDataTable and LoadSequence LINQ to DataSet query operators.





Re: LINQ Project General Looking for ToDataTable()

Terry Adams

This is not supported by Linq to SQL, and you will need to code this.






Re: LINQ Project General Looking for ToDataTable()

Andrew Conrad - MSFT

In VS 2008 - we support CopyToDataTable<T> as Linq sequence operator. This means you can write code like this:

DataTable newParksTable = (from park in parksDataTable.AsEnumerable()

where park.Field<int >("YearEstablished") < 1960

orderby park.Field<int >("YearEstablished")

select park).CopyToDataTable();

This works as long as the type of the projection is DataRow or a derived type.

We are not supporting this scenario when T is not DataRow. As Fabrice pointed out, we have released a sample of how to do this here. (it will also be part of the Orcas documentation).





Re: LINQ Project General Looking for ToDataTable()

Fabrice MARGUERIE

Terry, please see my reply above. It works with any LINQ query, including LINQ to SQL.