Erro when Performing Filter using DataOperations

Hi, I have a DataManager perfoming filtering on my page, its a Custom Adaptor

I'm using it on DropDownList and ComboBox

it works fine except when The IQueryable object passed to the funcion is a IIncludableQueryable (EntityFramework extentions)


So I have an DataManagerRequest object with Where clauses

and I'm trying to perform the filter using

registros = DataOperations.PerformFiltering(registros,dm.Where,"AND");

where dm is  DataManagerRequest 

And the following exception is occoring:

An exception of type 'System.ArgumentNullException' occurred in System.Linq.Expressions.dll but was not handled in user code: 'Value cannot be null.'


   at System.Linq.Expressions.Expression.Validate(Type type, Boolean allowByRef)

   at System.Linq.Expressions.Expression.Parameter(Type type, String name)

   at Syncfusion.Blazor.Data.QueryableExtensions.Parameter(Type sourceType)

   at Syncfusion.Blazor.Data.QueryableOperation.PerformFiltering[T](IQueryable`1 dataSource, List`1 whereFilter, String condition)

   at Syncfusion.Blazor.DataOperations.PerformFiltering[T](IQueryable`1 dataSource, List`1 whereFilter, String condition)

   at NCPC.Web.Controllers.ApiController`2.Listar(DataManagerRequest dm) in C:\Projetos\NCPC\NCPC.Web\Controllers\ApiController.cs:line 50

   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)

   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()

   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)

   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()


Is there a Workaround for this issue? I've tryied to call AsQueryable on my IIncludableQueryable but it doesn't 


4 Replies

JP Jeevakanth Palaniappan Syncfusion Team August 6, 2021 12:06 PM UTC

Hi Daniel, 

Greetings from Syncfusion support. 

We have checked your query but to proceed further, we need the following details to validate the problem from our side. 

  1. Share us the Syncfusion NuGet version details.
  2. Kindly share us the issue reproducing sample.
  3. Share us the video demo showing the reported problem.

The above requested details will be helpful for us to validate the problem and to provide you with a better solution as early as possible. 

Regards, 
Jeevakanth SP. 



DA Daniel August 6, 2021 12:34 PM UTC

Hi, I've attached a sample ( this sample was provided by Syncfusion team)

I modified the sample so the error happens

You will have to filter something on the grid



After filtering something, the error happens

I added an .Include on the query

DataSource = DataSource.AsQueryable().Include(x => x.OrderDate);

var test = DataSource.ToList();

Filtering

DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);


I Also added Microsoft.EntityFrameworkCore Nuget package






Attachment: BlazorApp_7df580cf.7z


JP Jeevakanth Palaniappan Syncfusion Team August 9, 2021 02:32 PM UTC

Hi Daniel, 

Thanks for sharing the issue reproducing sample. 

We are currently validating the reported problem and so we will update the further details in two business days. Until then we appreciate your patience. 

Regards, 
Jeevakanth SP. 



JP Jeevakanth Palaniappan Syncfusion Team August 11, 2021 03:18 PM UTC

Hi Daniel, 

Thanks for your patience. 

We have checked your sample and the issue occurs due to using the Include method. The include method will be used only for the complex fields present in your model class. But in your sample, there is no complex properties. Can you please share why you have used like this? Is there any specific reason for this? 

Also we have modified your sample to do filtering with the Include method with complex properties. Please refer the below code snippet and the sample for your reference. 


<SfGrid @ref="Grid" Query="GridQuery" TValue="Order" AllowPaging="true" AllowFiltering="true"> 
    <SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager> 
    <GridEvents TValue="Order" OnActionFailure="FailureAction"></GridEvents> 
    <GridPageSettings PageSize="8"></GridPageSettings> 
<GridColumns> 
    <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
    <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> 
    <GridColumn Field="@(nameof(Order.Emp) + "." + nameof(Employee.TerritoryID))" HeaderText="ID" Width="150"></GridColumn> 
    <GridColumn Field=@nameof(Order.EmployeeID) Width="150"></GridColumn> 
</GridColumns> 
</SfGrid> 
 
@code{ 
    public static List<Order> Orders { get; set; } 
    Query GridQuery { get; set; } 
 
    protected override void OnInitialized() 
    { 
        Orders = Enumerable.Range(1, 75).Select(x => new Order() 
        { 
            OrderID = 1000 + x, 
            CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)], 
            EmployeeID = x, 
            Emp = new Employee() { 
                EmployeeID = x, 
                TerritoryID = "Territory"+x, 
            } 
       }).ToList(); 
        GridQuery = new Query().Expand(new List<string>() { "Emp", }); 
    } 
 
    public class Order 
    { 
       [Key] 
        public int OrderID { get; set; } 
        [Required] 
        public string CustomerID { get; set; } 
        [Required] 
        public int EmployeeID { get; set; } 
        [ForeignKey("EmployeeID")] 
        public virtual Employee Emp { get; set; } 
    } 
    public class Employee 
    { 
        [Key] 
        public int EmployeeID { get; set; } 
        [Required] 
        public string TerritoryID { get; set; } 
    } 
    public class CustomAdaptor : DataAdaptor 
    { 
        // Performs data Read operation 
        public override object Read(DataManagerRequest dm, string key = null) 
        { 
            IQueryable<Order> DataSource = Orders.AsQueryable(); 
            if (dm.Expand != null && dm.Expand.Count() > 0) 
            { 
                foreach (string p in dm.Expand) 
                { 
                    DataSource = DataSource.Include(p); 
                } 
            } 
            .. 
           if (dm.Where != null && dm.Where.Count > 0) 
            { 
               DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator); 
            } 
            return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource; 
        } 
    } 
} 


Get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 


Loader.
Up arrow icon