Dotnet Core EJ2 Grid - DataManagerRequest Filtering on column from included object

I'm currently trying to have a view which shows Site model objects in a Grid.
Site Model objects includes a Customer Model object.

public class Site
{
        [Key]
        public long SiteId { get; set; } = 0;
        public long CustomerId { get; set; }
        public virtual Customer Customer { get; set; }
        public string Name { get; set; }
        public string Adress1 { get; set; }
}

public class Customer
{
        [Key]
        public long CustomerId { get; set; } = 0;
        public string Name { get; set; }
}

In the model when I ask for base Site model fields and also included Customer fields it's displayed correctly :
<ejs-grid id="SiteGrid" locale="fr-FR" allowSorting="true" allowFiltering="true")">
    <e-data-manager url="https://localhost:44350/api/Site/UrlDatasource" crossdomain="true" adaptor="UrlAdaptor"></e-data-manager>
    <e-grid-columns>
        <e-grid-column field="SiteId" headerText=@Localizer["ID"].Value type="number" width="20" textAlign="Right" isIdentity="true" allowEditing="false"></e-grid-column>
        <e-grid-column field="Customer.Name" headerText=@Localizer["Customer name"].Value type="string" width="75" isIdentity="true" allowEditing="false"></e-grid-column>
        <e-grid-column field="Customer.CustomerId" headerText=@Localizer["Customer Id"].Value type="string" width="20" isIdentity="true" allowEditing="false"></e-grid-column>
        <e-grid-column field="Adress1" headerText=@Localizer["Adress1"].Value type="string" width="75"></e-grid-column>
    </e-grid-columns>
</ejs-grid>

But when I try to filter on a column which belong to the Customer object (sub object), I got the following error :

System.InvalidOperationException : 'Processing of the LINQ expression 'DbSet<Site>
    .Include("Customer")
    .Select((a, i) => new { 
        a = a, 
        TempData = __ToList_0.get_Item(i)
     })' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.'


[HttpPost]
        public IActionResult UrlDatasource([FromBody] DataManagerRequest dm)
        {

            IEnumerable<Site> sites = _context.Site.Include("Customer").AsEnumerable();
            DataOperations operation = new DataOperations();

            if (dm.Search != null && dm.Search.Count > 0)
            {
                sites = operation.PerformSearching(sites, dm.Search);  //Search 
            }
            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting 
            {
                sites = operation.PerformSorting(sites, dm.Sorted);
            }
            if (dm.Where != null && dm.Where.Count > 0)
            {
                sites = operation.PerformFiltering(sites, dm.Where, dm.Where[0].Operator);     //Filtering 
            }

            if (dm.Skip != 0)
            {
                sites = operation.PerformSkip(sites, dm.Skip);   //Paging 
            }
            if (dm.Take != 0)
            {
                sites = operation.PerformTake(sites, dm.Take);
            }
            return Ok(new { result = sites, count = sites.Count() });

        }

Could you fix this problem or explain how to achieve the filtering ?

Best regards,
Romain

1 Reply 1 reply marked as answer

RS Rajapandiyan Settu Syncfusion Team September 3, 2020 01:06 PM UTC

Hi Romain, 
 
Greetings from syncfusion support. 
 
Query : when I try to filter on a column which belong to the Customer object (sub object), I got the following error : System.InvalidOperationException :  
 
we are unable to reproduce the reported problem at our end. Perform filtering in complex column is working fine, please find the below sample for your reference. 


We suspect that the issue may be raised because of some SerializerSettings. So, we suggest you to add the below code in your startup.cs file to overcome the problem. 
If the ASP.NET CORE version is 2.X then add the below code in startup.cs file 


public void ConfigureServices(IServiceCollection services) 
    services.AddMvc().AddJsonOptions(options => 
    { 
        options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver(); 
    }); 

 
 
If the ASP.NET CORE version is 3.X then add the below code in startup.cs file 
 
 
 
public void ConfigureServices(IServiceCollection services) 
          { 
                      services.AddMvc().AddNewtonsoftJson(options => 
          { 
                 options.SerializerSettings.ContractResolver = 
                    new DefaultContractResolver();
          }); 
             
        } 
 
 
To use AddNewtonsoftJson in your project we need include the Microsoft.AspNetCore.Mvc.NewtonsoftJson assembly 
 
 
 
Note : We need to install NewtonSoft.JSON as dependency since Syncfusion.EJ2.AspNet.Core dependent to NewtonSoft.JSON package. 
 
Refer to the below documentation for more information. 
 
 
Also refer to the solution of our old ticket have the same issue.

https://www.syncfusion.com/support/directtrac/incidents/272763 
 
If you still face the same problem, please share the below details to validate further on this.   
 
  1. Please share the issue reproduced sample (or) make the issue in the given sample and share with us.
  2. Share the startup.cs file in your project.
  3. Share the Syncfusion DLL version.
  4. Share the ASP.NET CORE version in your project.
  5. Share the video demo of the reported issue.
 
Regards, 
Rajapandiyan S

Marked as answer
Loader.
Up arrow icon