Blazor Grid grouping error when using SfDataManager Adaptors IQueryable (18.1.44)
Blazor Grid is giving following error when used with SfDataManager Adaptors IQueryable.
I have attached sample solution with MSSQL2017 database.
blazor.server.js:15 [2020-04-14T15:29:53.153Z] Error: System.InvalidCastException: Unable to cast object of type 'SyncfusionBlazorApp1.Database.Order' to type 'Syncfusion.Blazor.Data.Group`1[SyncfusionBlazorApp1.Database.Order]'.
at Syncfusion.Blazor.Grids.Internal.GroupModelGenerator`1.GenerateRows(IEnumerable data, Int32 startIndex)
at Syncfusion.Blazor.Grids.Internal.GridContent`1.OnParametersSet()
at Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.UpdateRetainedChildComponent(DiffContext& diffContext, Int32 oldComponentIndex, Int32 newComponentIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForFramesWithSameSequence(DiffContext& diffContext, Int32 oldFrameIndex, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
Attachment: SyncfusionBlazorApp1_a1e334.rar
SIGN IN To post a reply.
11 Replies
RS
Renjith Singh Rajendran
Syncfusion Team
April 15, 2020 12:07 PM UTC
Hi ashimaz,
Thanks for contacting Syncfusion support.
We suggest you to ensure to handle the Grouping codes in your application to overcome the problem you are facing. Please refer the below codes to handle the Grouping and add in your application.
|
public override object Read(DataManagerRequest dm, string key = null)
{
IQueryable<Database.Order> ResultData = _db.Order;
IEnumerable DataSource = ResultData.ToList();
DataResult DataObject = new DataResult();
...
if (dm.Sorted != null && dm.Sorted.Count > 0)
{
DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);
}
...
if (dm.Take != 0)
{
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
if (dm.Group != null)
{
foreach (var group in dm.Group)
{
DataSource = DataUtil.Group<Database.Order>(DataSource, group, dm.Aggregates, 0, dm.GroupByFormatter);
}
DataObject.Result = DataSource;
DataObject.Count = count;
return dm.RequiresCounts ? DataObject : (object)DataSource;
}
return dm.RequiresCounts ? new Syncfusion.Blazor.Data.DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
|
Please get back to us if you need further assistance.
Regards,
Renjith Singh Rajendran.
AS
ashimaz
April 16, 2020 01:39 AM UTC
Hi,
using IEnumerable DataSource = ResultData.ToList(); not efficient with large tables, is there any way to group without using IEnumerable ToList?
RS
Renjith Singh Rajendran
Syncfusion Team
April 16, 2020 09:32 AM UTC
Hi ashimaz,
Thanks for your update.
Based on your query, we suggest you to use the below code instead of the previously suggested way to achieve your requirement. Please use the code below,
|
public override object Read(DataManagerRequest dm, string key = null)
{
IQueryable<Database.Order> DataSource = _db.Order;
DataResult DataObject = new DataResult();
if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = DataOperations.PerformSearching(DataSource, dm.Search);
}
...
if (dm.Take != 0)
{
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
if (dm.Group != null)
{
IEnumerable ResultData = Enumerable.Empty<Database.Order>();
foreach (var group in dm.Group)
{
ResultData = DataUtil.Group<Database.Order>(DataSource, group, dm.Aggregates, 0, dm.GroupByFormatter);
}
DataObject.Result = ResultData;
DataObject.Count = count;
return dm.RequiresCounts ? DataObject : (object)ResultData;
}
return dm.RequiresCounts ? new Syncfusion.Blazor.Data.DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
|
Please get back to us if you need further assistance.
Regards,
Renjith Singh Rajendran.
AS
ashimaz
April 16, 2020 10:54 AM UTC
Hi, I am unable to try as mentioned. Please find solution file attached.

Attachment: SyncfusionBlazorApp1_f868b65.rar
Attachment: SyncfusionBlazorApp1_f868b65.rar
RS
Renjith Singh Rajendran
Syncfusion Team
April 17, 2020 09:55 AM UTC
Hi ashimaz,
We suggest you to ensure to add proper namespace for IEnumerable to overcome the problem you are facing. Please add the below namespace to your DataGridFeatures.razor file to overcome this error. And also please modify the below highlighted codes inside the dm.Group if loop condition in your application.
|
@using System.Collections
@code{
...
public class CustomAdaptor : DataAdaptor
{
...
public override object Read(DataManagerRequest dm, string key = null)
{
IQueryable<Database.Order> DataSource = _db.Order;
...
if (dm.Group != null)
{
IEnumerable ResultData = DataSource.ToList();
// Grouping
foreach (var group in dm.Group)
{
ResultData = DataUtil.Group<Data.Order>(ResultData, group, dm.Aggregates, 0, dm.GroupByFormatter);
}
DataObject.Result = ResultData;
DataObject.Count = count;
return dm.RequiresCounts ? DataObject : (object)ResultData;
}
return dm.RequiresCounts ? new Syncfusion.Blazor.Data.DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
...
}
}
|
As we faced some SQL network related problem with your attached sample, we are attaching a sample similar to your case and codes to perform Grouping in Grid. Please download the sample from the link below,
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/SyncfusionBlazorApp1-2056559218
Please get back to us if you need further assistance.
Regards,
Renjith Singh Rajendran.
AS
ashimaz
April 18, 2020 07:31 AM UTC
My apologies, I totally forgot to add name space @using System.Collections.
Provided solution is working.
Thank you.
Please find working code for reference.
public class CustomAdaptor : DataAdaptor { private Database.SyncfusionBlazorApp1Context _db = new Database.SyncfusionBlazorApp1Context(); // Performs data Read operation public override object Read(DataManagerRequest dm, string key = null) { IQueryable.Order> DataSource = _db.Order; DataResult DataObject = new DataResult(); if (dm.Search != null && dm.Search.Count > 0) { // Searching DataSource = DataOperations.PerformSearching(DataSource, dm.Search); } if (dm.Sorted != null && dm.Sorted.Count > 0) { // Sorting DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted); } if (dm.Where != null && dm.Where.Count > 0) { // Filtering DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator); } int count = DataSource.Cast .Order>().Count(); if (dm.Skip != 0) { //Paging DataSource = DataOperations.PerformSkip(DataSource, dm.Skip); } if (dm.Take != 0) { DataSource = DataOperations.PerformTake(DataSource, dm.Take); } if (dm.Group != null) { IEnumerable ResultData = Enumerable.Empty .Order>(); foreach (var group in dm.Group) { ResultData = DataUtil.Group .Order>(DataSource, group, dm.Aggregates, 0, dm.GroupByFormatter); } DataObject.Result = ResultData; DataObject.Count = count; return dm.RequiresCounts ? DataObject : (object)DataSource; } return dm.RequiresCounts ? new Syncfusion.Blazor.Data.DataResult() { Result = DataSource, Count = count } : (object)DataSource; } public void Dispose() { _db = null; Dispose(true); } }
RS
Renjith Singh Rajendran
Syncfusion Team
April 20, 2020 11:04 AM UTC
Hi ashimaz,
Thanks for your update.
We are glad to hear that you have achieved your requirement.
Please get back to us if you need further assistance.
Regards,
Renjith Singh Rajendran.
AS
ashimaz
May 21, 2020 10:36 PM UTC
Hi,

I am trying to use same code in a Web API, and I receive following error on filtering.
Grid
<SfDataManager Url="/api/SystemUser" Adaptor="Adaptors.UrlAdaptor">SfDataManager>
RS
Renjith Singh Rajendran
Syncfusion Team
May 22, 2020 09:47 AM UTC
Hi ashimaz,
Greetings from Syncfusion support.
We suggest you to ensure to add the below code highlighted code in your Startup.cs file to overcome the problem you are facing.
|
public void ConfigureServices(IServiceCollection services)
{
...
services.AddSyncfusionBlazor();
services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
...
}
|
For this we need to install the below package in your application,
Please get back to us if you need further assistance.
Regards,
Renjith Singh Rajendran
AS
ashimaz
May 22, 2020 12:14 PM UTC
Thank you, its working.
RS
Renjith Singh Rajendran
Syncfusion Team
May 25, 2020 07:01 AM UTC
Hi ashimaz,
Thanks for your update.
We are glad to hear that the provided suggestion helped you in overcoming the reported problem.
Please get back to us if you need further assistance.
Regards,
Renjith Singh Rajendran
SIGN IN To post a reply.
- 11 Replies
- 2 Participants
-
AS ashimaz
- Apr 14, 2020 03:40 PM UTC
- May 25, 2020 07:01 AM UTC