dotnet / EntityFramework.Docs

Documentation for Entity Framework Core and Entity Framework 6
https://docs.microsoft.com/ef/
Creative Commons Attribution 4.0 International
1.6k stars 1.95k forks source link

Local queries are case sensitive #3495

Open steffepeffe opened 2 years ago

steffepeffe commented 2 years ago

Hi,

In working with local view of my data, I discovered an inconsistency. I wasn't able to find any documentation regarding this. Is this a bug or is it by design somehow?

            dbContext.Platforms.SingleOrDefault(p => p.Id == "beleco").ShouldNotBeNull();
            dbContext.Platforms.SingleOrDefault(p => p.Id == "Beleco").ShouldNotBeNull();
            dbContext.Platforms.Load();
            dbContext.Platforms.Local.SingleOrDefault(p => p.Id == "beleco").ShouldNotBeNull();
            dbContext.Platforms.Local.SingleOrDefault(p => p.Id == "Beleco").ShouldNotBeNull(); // Fails!

EF Core version: 5.0.11 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 5.0 Operating system: Windows IDE: Jetbrains Rider 2021.2.1

Thanks!

ajcvickers commented 2 years ago

@steffepeffe See Collations and Case Sensitivity. In a nutshell, different databases do different things that may or may not align with the .NET behavior. It is by-design that queries run based on the native behavior of the platform, even if this is different from what LINQ to Objects does locally.

steffepeffe commented 2 years ago

Thanks @ajcvickers! Just to clarify, the surprise to me was not that the DB query is case insensitive. That part is clearly described in the link you provided. I'm more surprised that the LocalView does not "inherit" properties from the DB Collation. If I view the LocalView as a regular collection of Objects as your answer indicates, the behavior make sense. Perhaps this should be pointed out in the documentation?

ajcvickers commented 2 years ago

@steffepeffe Since the local view is just an IEnumerbale, the queries are just LINQ to Objects queries. EF Core isn't actually involved at all. But yes, we could explicitly call this out in the docs.