Skip to content

Errors compiling optimized DbContext that contains fixed length property #2974

@miegir

Description

@miegir

Steps to reproduce:

  1. In an empty folder, create a new console application: dotnet ef console
  2. Replace Program.cs with the following code:
using Microsoft.EntityFrameworkCore;

Console.WriteLine("Hello world!");

public class Entity
{
    public int Id { get; set; }
    public string? Name { get; set; }
}

public class ApplicationDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseNpgsql();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Entity>().Property(t => t.Name).HasMaxLength(10).IsFixedLength();
    }
}
  1. Execute dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
  2. Execute dotnet add package Microsoft.EntityFrameworkCore.Design
  3. Execute dotnet new tool-manifest
  4. Execute dotnet tool install dotnet-ef
  5. Execute dotnet ef dbcontext optimize
  6. Execute dotnet build

Expected behavior: the application will compile.

Actual behavior: compilation errors:

D:\ghbug\CompiledModels\EntityEntityType.cs(58,78): error CS0117: 'NpgsqlCharacterStringTypeMapping' does not contain a definition for 'EqualsWithoutTrailingWhitespace' [D:\ghbug\ghbug.csproj]
D:\ghbug\CompiledModels\EntityEntityType.cs(59,68): error CS0117: 'NpgsqlCharacterStringTypeMapping' does not contain a definition for 'GetHashCodeWithoutTrailingWhitespace' [D:\ghbug\ghbug.csproj]
D:\ghbug\CompiledModels\EntityEntityType.cs(62,78): error CS0117: 'NpgsqlCharacterStringTypeMapping' does not contain a definition for 'EqualsWithoutTrailingWhitespace' [D:\ghbug\ghbug.csproj]
D:\ghbug\CompiledModels\EntityEntityType.cs(63,68): error CS0117: 'NpgsqlCharacterStringTypeMapping' does not contain a definition for 'GetHashCodeWithoutTrailingWhitespace' [D:\ghbug\ghbug.csproj]
D:\ghbug\CompiledModels\EntityEntityType.cs(66,78): error CS0117: 'NpgsqlCharacterStringTypeMapping' does not contain a definition for 'EqualsWithoutTrailingWhitespace' [D:\ghbug\ghbug.csproj]
D:\ghbug\CompiledModels\EntityEntityType.cs(67,68): error CS0117: 'NpgsqlCharacterStringTypeMapping' does not contain a definition for 'GetHashCodeWithoutTrailingWhitespace' [D:\ghbug\ghbug.csproj]

This technique worked with Npgsql.EntityFrameworkCore.PostgreSQL version 7.0 but stopped working with 8.0 in which these methods were removed.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions