开发者

LINQ query to DataTable type error

I have the following function in by Data Access Layer but I am receiving the following error on my RETURN statement.

The type arguments for method 'System.Data.DataTableExtensions.CopyToDataTable(System.Collections.Generic.IEnumerable)' cannot be inferred from the usage. Try specifying the type arguments explicitly

My code is:

DL.FVRGDataContext db = new FVRGDataContext();

public DataTable getRestaurants(string cuisineName)
{
   var cuisineIdFind = from CUISINE in db.CUISINEs
                       where CUISINE.CUISINE_NAME == cuisineName
                       select CUISINE.CUISINE_ID;

   var restaurantList = from RESTAURANT in db.RESTAURANTs
                        where RESTAURANT.CUISINE_ID == 2
                        orderby RESTAURANT.REST_NAME ascending
                        select i;

   DataTable result = new DataTable();
   result = restaurantList.Cop开发者_Go百科yToDataTable();

   return result;
}


CopyToDataTable doesn't work this way... it has a generic parameter T, where T must be a subclass of DataRow. In other words CopyToDataTable can't be used to convert an arbitrary collection to DataTable, the items of the collection must be DataRows themselves.

In your case, CUISINE and RESTAURANT seem to be Linq to SQL or Entity Framework entities, not DataRows, so it can't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜