I am using entity framework with the following linq query
IQueryable<Order_Details> query = (from ord in ctx1.Order_Details
where ord.OrderID == 1
select ord).ToArray();
gv1.DataSource = query;
gv1.DataBind();
I get a result ok, return a row with orderId of 1
When I use the following,
var query = (from ord in ctx1.Order_Details
where ord.OrderID == 1
select ord).First() as IQueryable<Order_Details>;
gv1.DataSource = query;
gv1.DataBind();
I don’t recive any results in the gridview
First() returns the Order_Detail record itself, not a collection/array, and therefore is not IQueryable; so using
as IQueryable<Order_Details>will return null because it can’t be cast. Casting to IQueryable<> can only work for an enumerable of some sort.If you have to use First, bind to the gridview like this: