Question

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?

Était-ce utile?

La 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:

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top