We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Filtering ForeignKey field raises an exception

Hello Syncfusion Team,
I'm working with the Grid control.

The grid show a nested entity throught:

col.Field(x => x.Categoria.Id).HeaderText("Categoria")
                                .ForeignKeyField("Id").ForeignKeyValue("Nome")
                                .DataSource(ViewBag.Categorie)
                                .EditType(EditingType.Dropdown)
                                .Add();

I want to filter this column (filtering is enabled in grid).

When I write something on the filter textbox the action called is:

[HttpPost]
        public JsonResult Lista(DataManager dm)
        {
            using (DataDbContext db = new DataDbContext())
            {
                IEnumerable data = db.Pazienti;
                DataOperations operation = new DataOperations();
                data = operation.Execute(data, dm);
                List<PazienteViewModel.Index> result = data.Cast<Paziente>().AsQueryable().OrderBy(x => x.Cognome).ThenBy(x => x.Nome).ProjectToList<PazienteViewModel.Index>();

                return Json(new { result, count = result.Count });
            }
        }

Executing this code, I get an exception on the highlighted line.

System.NullReferenceException non è stata gestita dal codice utente
  HResult=-2147467261
  Message=Riferimento a un oggetto non impostato su un'istanza di oggetto.
  Source=Syncfusion.EJ
  StackTrace:
       in Syncfusion.JavaScript.DataSources.DataOperations.PerformWhereFilter(IEnumerable dataSource, List`1 whereFilter, String condition)
       in Syncfusion.JavaScript.DataSources.DataOperations.Execute(IEnumerable dataSource, DataManager manager)
       in PazientiController.Lista(DataManager dm) in PazientiController.cs:riga 36
       in lambda_method(Closure , ControllerBase , Object[] )
       in System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       in System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       in System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       in System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
       in System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
       in System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
       in System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
       in System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
       in System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
  InnerException: 

How can I solve this problem? What am I doing wrong?

3 Replies

GV Gowthami V Syncfusion Team March 9, 2016 09:24 AM UTC

Hi Omar,

We have analyzed your issue and we are unable to reproduce the issue.

For your reference we have attached the sample (version 13.4.0.63) below,

http://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample-387324481.zip

Please provide us below details to reproduce the issue.

1.       Share the code example used for grid rendering.

2.       Share the version details that you have used.

3.       Reproduce the issue in the above sample.

The provide information will help to analyze the issue and provide you the response as early as possible.

Regards,

Gowthami V.



OM Omar Muscatello March 9, 2016 05:20 PM UTC

Thank you Gowthami V.

Comparing your example with mine I found the problem.

I have to use x.IdCategoria and not x.Categoria.Id

So I think that there is a problem with nested entities.

Thank you again.


GV Gowthami V Syncfusion Team March 10, 2016 04:04 AM UTC

Hi Omar,
 
We are happy to hear that your issue has been resolved.
 
Get back to us if you need further assistance.
 
Regards,
 
Gowthami V.

Loader.
Live Chat Icon For mobile
Up arrow icon