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?
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:
ExecuteQueryreturns:a collection ofIEnumerable<T>. Then you can convert this list to a datatable. You can use the following function to convert it to a datatable: