LINQ to SQL(.dbml): how do ExecuteQuery method return DataTable?
c#, datatable, executequery, linq, linq-to-sql
Solution
You shouldn't do this. Why then bothering yourself with LINQ-To-SQL and just use normal ADO methods to get a normal datatable object. This isn't what LINQ-to-SQL is for. You should think in terms of objects.
But, if you need to do this any way: `ExecuteQuery` returns:a collection of `IEnumerable<T>`. Then you can convert this list to a datatable. You can use the following function to convert it to a datatable:
- Convert List/IEnumerable to DataTable/DataView
Problem
``` var products = db.ExecuteQuery<Product>( "SELECT ProductID, ProductName " + "FROM Products " + "WHERE Discontinued = 0 " + "ORDER BY ProductName;" ); ``` above query works fine but is there any way `db.ExecuteQuery<Product>` returns `DataTable Product` instead of `var products`?