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.CopyToDataTable();
return result;
}
CopyToDataTabledoesn’t work this way… it has a generic parameterT, whereTmust be a subclass ofDataRow. In other wordsCopyToDataTablecan’t be used to convert an arbitrary collection toDataTable, the items of the collection must beDataRowsthemselves.In your case,
CUISINEandRESTAURANTseem to be Linq to SQL or Entity Framework entities, notDataRows, so it can’t work.