Datagrid sortproperty problem since last update

Hello,

I updated from Radzen.Blazor de 3.2.9 à 3.13.5.
Since the update, I have a problem with the SortProperty on several datagrids.

 <RadzenGridColumn TItem="ViewModels.EstimateRow" Property="EstimateWithCount.Estimate.ClientCode" SortProperty="Estimate.ClientCode" Title="Client Code" Filterable="false" Width="100px">
</RadzenGridColumn>

Before the Update, I would have "EstimateCart.ClientCode desc" or "EstimateCart.ClientCode asc" in the args.OrderBy Property of the LoadDataArgs parameter.

Now, I have 'np(EstimateCart.ClientCode) desc'. I don't why the np(...) is added.

If I have a simpler Property with just one level, as SortProperty="ClientCode", I don't have the problem.

Thank you for your help,

Regards,

Elisa.

Hi @Elisa,

This is Dynamic LINQ expression and it was added to handle null values in complex properties. Before this fix EstimateCart.ClientCode will throw exception if EstimateCart is null.

Hello, I have a problem with the null propagating expression added to Radzen Grid.

With the previous version of the grid, without the null propagating expression, I had this query expression:

DbSet()
.Select(b => new Brand{
Id = b.Id,
Name = b.Name,
Stat = new BrandStat{
ProductCount = <>c__DisplayClass18_0.dbContext.Products
.Where(p => p.BrandId == (Guid?)b.Id)
.Select(p => p.Id)
.Count(),
PublishedProductCount = <>c__DisplayClass18_0.dbContext.Products
.Where(p => p.BrandId == (Guid?)b.Id && p.State = 1)
.Select(p => p.Id)
.Count()
}
}
)
.OrderBy( => .Stat.ProductCount)

This query worked and the grid was sorted using the ProductCount column within the Stat property.

With the null propagating expression in the OrderBy statement, the query transforms to:

DbSet()
.Select(b => new Brand{
Id = b.Id,
Name = b.Name,
Stat = new BrandStat{
ProductCount = <>c__DisplayClass18_0.dbContext.Products
.Where(p => p.BrandId == (Guid?)b.Id)
.Select(p => p.Id)
.Count(),
PublishedProductCount = <>c__DisplayClass18_0.dbContext.Products
.Where(p => p.BrandId == (Guid?)b.Id && p.State = 1)
.Select(p => p.Id)
.Count()
}
}
)
.OrderBy( => != null && .Stat != null ? (int?).Stat.ProductCount : null)

And I get the error:

The LINQ expression [...] could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See Client vs. Server Evaluation - EF Core | Microsoft Docs for more information.

Could you please help me with this?
Thanks in advance.

Best Regards,
Arianne

Hi @arianne,

What is your query provider? We cannot reproduce such error locally - for example sorting on our Sample database Order Details complex properties with Microsoft SQL Server:


I see however that you have Select expression that will create new object new Brand{} - this definitely cannot be translated.

Hello,

Thanks for your quick answer.

I use Microsoft SQL Server. The query is generated with Dynamic Linq using the order by expression from the Grid:

query = DynamicQueryableExtensions.OrderBy(query, filter.StringOrderBy);

Without the np() operator the query is translated with no problem, even with the new Brand {} object:

SELECT [b].[Id], [b].[Name], (
SELECT COUNT()
FROM [Product] AS [p0]
WHERE [p0].[BrandId] = [b].[Id]) AS [ProductCount], (
SELECT COUNT(
)
FROM [Product] AS [p1]
WHERE [p1].[BrandId] = [b].[Id] AND [p1].State = 1) AS [PublishedProductCount]
FROM [Brand] AS [b]
ORDER BY (
SELECT COUNT(*)
FROM [Product] AS [p]
WHERE [p].[BrandId] = [b].[Id])

The problem arises when the np() operator is sent by the grid. Is there any way to avoid having the np() sent for complex grid columns ?

Thanks in advance.

Hey @arianne,

I'll repeat myself: Select with new object cannot be translated to SQL and there is not Select with projection in the SQL you've posted:

There is no way to remove null propagation expression for complex properties when the DataGrid is bound to IQueryable however you can use LoadData to perform your own sorting using the information provided in the event argument.