Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Andrey-2021 opened this issue Feb 13, 2024 · 6 comments
Closed
Assignees
Labels

Comments

@Andrey-2021
Copy link

Andrey-2021 commented Feb 13, 2024

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

@Andrey-2021 Andrey-2021 changed the title C# Entity Framework Core - OrderBy and Wher don't work with [ComplexType] C# Entity Framework Core - OrderBy and Where don't work with [ComplexType] Feb 13, 2024
@StefH StefH self-assigned this Feb 14, 2024
@StefH StefH added the question label Feb 14, 2024
@StefH
Copy link
Collaborator

StefH commented Feb 14, 2024

Hello @Andrey-2021,

I did add your test project in this PR (#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
Copy link
Author

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
Copy link
Collaborator

StefH commented Feb 14, 2024

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

@Andrey-2021
Copy link
Author

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

image

@StefH
Copy link
Collaborator

StefH commented Feb 14, 2024

Please use my solution in the PR:

2024-02-14_18h01_30

@Andrey-2021
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants