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

[Question] OrderBy does not work with nullable navigation properties #400

Closed
khallid-itdevtech opened this issue Jul 14, 2020 · 4 comments
Closed
Assignees

Comments

@khallid-itdevtech
Copy link

OrderBy works fine on non nullable navigation properties but if navigation property is nullable it doesn't work

System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseArgumentList() in ExpressionParser.cs, line 1851

list = list.AsQueryable().OrderBy("site.title asc" ).ToList();

site is nullable navigation property

@JonathanMagnan JonathanMagnan self-assigned this Jul 14, 2020
@JonathanMagnan
Copy link
Member

Hello @khallid-itdevtech ,

Do you think you could provide a project sample with this issue?

It will help my developer investigate the issue more efficiently.

We already tried once but everything was working, so we might miss something.

We now always ask for a project sample even if the issue is easy to reproduce. As a free product, we must find some way to save time to offer an overall better experience for everyone and release fixes faster.

You can send it to: [email protected] if you need to keep the source private

Best Regards,

Jonathan


Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval FunctionSQL Eval Function

@StefH
Copy link
Collaborator

StefH commented Jul 14, 2020

I think the site is a nullable navigation property in this question. So you cannot use site.title asc because site is null.

The solution is to use the NullPropagating (np) function, so I think this code should solve the issue

list = list.AsQueryable().OrderBy("np(site.title) asc" ).ToList();

@JonathanMagnan
Copy link
Member

I was getting a different error when the site was null (Null reference exception which is was I'm expecting).

I guess we will see with his answer ;)

@khallid-itdevtech
Copy link
Author

@StefH Thanks
list = list.AsQueryable().OrderBy("np(site.title) asc" ).ToList();
this works like charm. 👍

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

No branches or pull requests

3 participants