Search code examples
c#entity-framework.net-corenpgsql.net-core-3.0

EF Core 3.0 replacement for IMutableIndex.Npgsql() method


In our existing project (using Entity Framework Core 2.2 and Npgsql) we have the following piece of code in our DB Context:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    ...
    var entityTypes = modelBuilder.Model.GetEntityTypes().Where(x => !x.IsQueryType);
    foreach (var entityType in entityTypes)
    {
        var indexes = entityType.GetIndexes();

        foreach (var index in indexes)
        {
            index.Npgsql().Name = GetCustomIndexName(index.Npgsql().Name, entityType);
        }
    }
    ...
}

When migrating to .NET Core 3.0, there are a lot of breaking changes. One of them is the property IsQueryType. Based on this part of documentation, I changed the property to IsKeyless, which should be equivalent.

However, since the documentation is so sparse and sometimes non-existent, I have a hard time figuring out what to substitute for index.Npgsql().Name. Visual Studio is displaying an error message underneath the Npgsql() extension method, saying Reference to type 'RelationalKeyAnnotations' claims it is defined in 'Microsoft.EntityFrameworkCore.Relational', but it could not be found.

Based on another piece of documentation, I would assume that the correct equivalent is index.GetNpgsqlName(), but it seems no such method exists. Do I need to install any additional Nuget packages in order to get the correct extension method? Or is there a different approach to get and set the provider-specific index names?


Solution

  • Thanks for trying out the prerelease version, as you've noticed things are in flux and not entirely stable!

    I am currently actively working on porting the Npgsql EF provider to preview7 (which is about the be released), and have specifically worked on metadata accessors. So I'd recommend waiting for another week or so and switching to preview7.