Query never returns when DB value for column mapped to primitive collection is '' #32896
Description
Problem
When using EF to query an entity that has a primitive collection property the query never returns if the database value of the column is ''
The database query appears to execute successfully, but nothing more happens. The method never returns.
This is the last thing logged, even with LogLevel set to Trace:
info: 23.01.2024 14:47:32.803 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "s"."Id", "s"."List"
FROM "SimpleEntities" AS "s"
LIMIT 1
Encountered this when adding a new column to an existing table. The generated migration sets the default value to ''
Tested with different collection types and primitives, Sqlite/SqlServer, and sync/async. Same result for everything I tested with.
Update: Left the repro running over night, the FirstAsync method has still not returned.
Repro code
await using var connection = new SqliteConnection("DataSource=:memory:");
await connection.OpenAsync();
await using var ctx = new SimpleContext(connection);
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
await ctx.Database.ExecuteSqlRawAsync("INSERT INTO SimpleEntities (List) VALUES ('');");
var entity = await ctx.SimpleEntities.FirstAsync();
Console.WriteLine(entity);
public class SimpleContext(SqliteConnection connection) : DbContext
{
public DbSet<SimpleEntity> SimpleEntities => Set<SimpleEntity>();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlite(connection)
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}
}
public record SimpleEntity(int Id, IEnumerable<string>? List);
Include provider and version information
EF Core version: 8.0.1
Database provider: tested with Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.Sqlite
Target framework: .NET 8.0)
Operating system: Windows 11
IDE: VS Code