OrderBy NULL value throws "Incorrect syntax near the keyword IS NULL" error #8591
Labels
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
type-bug
Milestone
I have following entity in my project (.net core1.0/ef core1.0/vs2015)-
Now I want to return all news items first ordered by NULL rank and then by any integer value and lastly also ordered by date descending. This is the code in my repository that returns this data
return await context.News.OrderBy(x => x.UserDefinedRank == null).ThenBy(x => x.UserDefinedRank).ThenByDescending(x => x.Date).ToListAsync();
This generates following SQL which is incorrect (viewed in SQL profiler):
The same code in EF6.0 works flawlessly and generates:
If I comment the OrderBy(x => x.UserDefinedRank == null), it returns data but without the first condition that i really want.
Steps to reproduce
Use OrderBy clause in LINQ with NULL condition.
Further technical details
EF Core version: 1.0.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2015
The text was updated successfully, but these errors were encountered: