SQLite: Lower-case Guid strings don't work in queries
See original GitHub issueI use Microsoft.EntityFrameworkCore.Sqlite 3.1.1 in a testing project (with SqlServer used elsewhere). I expect it to be a (mostly) drop-in alternative. However, this doesn’t work as expected with SQLite (but works fine with SqlServer and InMemory):
public IQueryable<Item> Query(Guid? tenantId, string? tag = null)
{
var entities = this.dbContext.Items
.Include(a => a.Tags)
.Where(a => tag == null || a.Tags.Any(at => at.TenantId == tenantId && at.Tag == tag))
...
entities
is empty, while it’s expected to contain some items.
Upon checking a whole bunch of Guid-related issues here, the only workaround I found requires changing OnModelCreating
(adding .HasConversion<string>()
for the property helps), which is not acceptable since the same code works with other providers. Therefore, I conclude that it’s a bug in the provider.
Tag.TenantId
is Guid?
. Database was created using context.Database.EnsureCreated();
. GUIDs are formatted as 00000000-0000-0000-0000-000000000000
(as per https://docs.microsoft.com/en-us/dotnet/standard/data/sqlite/types).
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:24 (9 by maintainers)
To mitigate future breaking changes in this area, I’d recommend converting all the database values to lowercase and using a value converter.
Comparing two Guid types is handled fine. I personally like to have Guid.TryParse on the outside of that line and have invalid formats checked beforehand. (Guid.Parse will throw)
Yes, AsEnumerable (even though it supposedly “streams” the data) is an impact on performance on large result sets, which you obviously have, since you need to query all elements of your DbSet. (according to documentation)