zzzprojects / System.Linq.Dynamic.Core

The .NET Standard / .NET Core version from the System Linq Dynamic functionality.
https://dynamic-linq.net/
Apache License 2.0
1.57k stars 228 forks source link

C# Entity Framework Core - OrderBy and Where don't work with `[ComplexType]` #778

Closed Andrey-2021 closed 8 months ago

Andrey-2021 commented 8 months ago

project: https://github.com/Andrey-2021/RadzenDataGrid use MsSQL + Entity Framework Core

image

1. Description

When I don't use OrderBy the program is work. But When I use OrderBy i Have Exception in method protected async Task OnLoadDataAsync(LoadDataArgs args) OrderBy and Where don't work with [ComplexType]

first class:

public class PriceListService
{
    [Key]
    public int Id { get; set; }

    [Required]
    public PriceListServiceBase ServiceBase { get; set; } = new();
}

second class:

[ComplexType]
public class PriceListServiceBase
{
    public int Index { get; set; }
    public string? Code { get; set; }
    public string? ServiceName { get; set; }
}

2. Exception

Exception: Comparing complex types to null is not supported. I see in line query = query.OrderBy(args.OrderBy); args.OrderBy = 'np(ServiceBase.Index) desc'

image

image

image

3. Fiddle or Project

https://github.com/Andrey-2021/RadzenDataGrid

To Reproduce Steps to reproduce the behavior:

  1. Load project https://github.com/Andrey-2021/RadzenDataGrid
  2. Config db connection string 'DefaultConnection' in appsettings.json
  3. Run project
  4. Click button 'First step -> Add Data to Db'
  5. try sort column Index or Code or Name in RadzenDataGrid we get an error: Exception: Comparing complex types to null is not supported.

image

StefH commented 8 months ago

Hello @Andrey-2021,

I did add your test project in this PR (https://github.com/zzzprojects/System.Linq.Dynamic.Core/pull/780) and when running on a InMemory database, it works fine. Can you use this example and connect it to your real database?

Andrey-2021 commented 8 months ago

Hi! I connected real db, please reload progect from https://github.com/Andrey-2021/RadzenDataGrid

Yes, OrderBy work when I use List in memory instead of a real database. But I have error with real MsSQL DataBase

StefH commented 8 months ago

@Andrey-2021 I did use your connection-string in my PR, and it still works fine? image

Andrey-2021 commented 8 months ago

an Exception occurs when it is necessary to sort, try to sort the columns: Index or Code or Name

image

StefH commented 8 months ago

Please use my solution in the PR:

2024-02-14_18h01_30

Andrey-2021 commented 8 months ago

Thank you very much!!!!!!!!!!!!!! Ity's work with the setup using OwnsOne()