Skip to content

IsPrimitiveCollection metadata is incorrect when using the compiled model #35047

Closed
@roji

Description

@roji

With the following repro, the Tags property has IsPrimitiveCollection=true, but when a compiled model is generated, IsPrimitiveCollection is false.

await using var context = new MainDbContext();

// The following prints True without the compiled model, False with
var tagsProperty = context.Model.GetEntityTypes().Single().FindProperty(nameof(Article.Tags));
Console.WriteLine($"IsPrimitiveCollection={tagsProperty.IsPrimitiveCollection}");

await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();

// Fails with the compiled model
_ = await context.Articles.Where(p => p.Tags.Any()).ToListAsync();

public class MainDbContext : DbContext
{
    public DbSet<Article> Articles { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseSqlServer("Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false")
            .LogTo(Console.WriteLine, LogLevel.Information)
            .EnableSensitiveDataLogging();
}

public class Article
{
    public string Id { get; set; } = null!;
    public string[] Tags { get; set; } = [];
}

This is the root cause of npgsql/efcore.pg#3168

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions