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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top