I have a grid that has filtering enabled. It works great on most columns, but if the column has a NULL value anywhere, it throws an exception.
I can duplicate this using the sample here:
https://es.infragistics.com/community/blogs/b/taz_abdeali/posts/asp-net-mvc-3-entity-framework-infragistics-jquery-grid
Add a new customer to the Northwind database, but leave some values null.
Then, modify the controller action to look like this:
[GridDataSourceAction] public ActionResult CustomerList() { List<Customer> ItemList = MVC3EntityFramework.Models.CustomerModel.GetCustomerList().ToList<Customer>(); return View(ItemList.AsQueryable<Customer>()); }
This will cause an error when you try to filter by any of the columns that have a NULL value. You can filter by columns that do not have NULL's just fine.
If you don't use the list and simply do this, it works:
return View(MVC3EntityFramework.Models.CustomerModel.GetCustomerList());
However, in my production code, I'm using a list then returning the list as an IQueriable (similar to above).
Any ideas?
Thanks,Tony
OK.
Simple answer:
I had to add
entityBuilder.ProviderConnectionString = entityBuilder.ProviderConnectionString +
";MultipleActiveResultSets=true";
Basically, I added MARS to the connection string to eliminate the error with using the LINQ results.AsQueryable<class>();
Since I no longer have to cast to a list, the filtering now works.
Still, you might want to address the issue with using a list.
Sorry, left out some information.
The stack trace and error above are what happen when I just take the LINQ result and pass it back .AsQueryable<class>() instead of just returning the list. This is why I have to first cast the result to a "List", which has now introduced the error while filtering a column with a null value.
Hopefully that all makes sense.
I'm intercepting the on exception of the controllerbase class and here is what I've found:
Inner Exception:
There is already an open DataReader associated with this Command which must be closed first.
Stack Trace:
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.IEnumerable.GetEnumerator() at Infragistics.Web.Mvc.GridModel.CheckNullables() at Infragistics.Web.Mvc.GridModel.DataBind() at Infragistics.Web.Mvc.GridModel.GetData() at Infragistics.Web.Mvc.GridDataSourceActionAttribute.OnActionExecuted(ActionExecutedContext filterContext) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)