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
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
|
<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.Emp) + "." + nameof(Employee.TerritoryID))" HeaderText="ID" 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;
}
}
}
|