Hi, I'm using the React Grid and consuming the data with the UrlAdaptor from my ASP.NET Core 3.1 backend. I'm able to fetch the data from the server and to display the records in the grid, as well as to sort and group them. However, when I'm filtering the data through the grid search box, I'm always getting the following errror:
System.InvalidCastException
HResult=0x80004002
Message=Invalid cast from 'System.String' to 'System.Guid'.
Source=System.Private.CoreLib
StackTrace:
at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
at System.String.System.IConvertible.ToType(Type type, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType)
at Syncfusion.EJ2.Base.QueryableOperation.PredicateBuilder[T](IQueryable`1 dataSource, List`1 whereFilter, String condition, ParameterExpression paramExpression, Type type)
at Syncfusion.EJ2.Base.QueryableOperation.PredicateBuilder[T](IQueryable`1 dataSource, List`1 whereFilter, String condition, ParameterExpression paramExpression, Type type)
at Syncfusion.EJ2.Base.QueryableOperation.PerformFiltering[T](IQueryable`1 dataSource, List`1 whereFilter, String condition)
at Syncfusion.EJ2.Base.DataOperations.PerformFiltering[T](IQueryable`1 dataSource, List`1 whereFilter, String condition)
My Url Adaptor controller looks like the following:
[HttpPost]
[Route("[action]")]
public ActionResult<Models.Task> UrlAdaptor([FromBody] DataManagerRequest dm)
{
var data = _context.Tasks.AsQueryable();
DataOperations operation = new DataOperations();
if (dm.Search != null && dm.Search.Count > 0)
{
data = operation.PerformSearching(data, dm.Search); //Search
}
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
data = operation.PerformSorting(data, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
data = operation.PerformFiltering(data, dm.Where, dm.Where[0].Operator); -----> ERROR
}
int count = data.Count();
if (dm.Skip != 0)
{
data = operation.PerformSkip(data, dm.Skip); //Paging
}
if (dm.Take != 0)
{
data = operation.PerformTake(data, dm.Take);
}
return dm.RequiresCounts ? Ok(new { result = data, count = count }) : Ok(data);
}
A single entry of the data collection of the grid looks like the following:
{"ID": "4f903fb5-ebb2-4b23-a2a1-428428a9cb03","Description": "Buy a new PC monitor","Done": false,"Priority": false,"PrivateOfID": "d5f1914c-0660-4583-99ec-4ff9bf6a001f","PrivateOf": null,"Private": true,"Progress": 0.2,"TaskCategoryID": "6a1e9cda-989d-444f-b131-3cad41b5bb49","TaskCategory": null,"DueDate": "2021-01-01T00:00:00","ContactID": null,"Contact": null,"RequestedByID": null,"RequestedBy": null,"ResponsibleForID": null,"ResponsibleFor": null,"CreatedAt": "2020-10-14T10:17:29.303705","CreatedByID": "02673469-9abc-4c4e-ad44-517bf2d45e23","CreatedBy": null,"CreatedByName": "Max Mustermann","UpdatedAt": "2020-10-14T10:17:29.303705","UpdatedByID": "02673469-9abc-4c4e-ad44-517bf2d45e23","UpdatedBy": null,"UpdatedByName": "Max Mustermann"},
1. Any idea how can I solve this problem?
2. By the way, is there somewhere a complete example on how I can use an ASP.NET Core 3.1 backend im combination with the Rest API Adaptor with a React Grid (instead of using the UrlAdaptor). In particular, I'm looking for an elegant way how to solve the filtering in combination with Linq (Entity framework)?