The call is ambiguous between the following methods or properties [ Entity Framework Core ] [ OnModelCreating ]

Viewed 1263

I use EF Core, inside my dbcontext class I have overridden the onModelCreating method to configure one property in a class to be auto-increment in SQL Server.

This is my DbContext class:

public class AppDbContext:IdentityDbContext<AppUser>
{
    public AppDbContext(DbContextOptions options) : base(options)
    {
    }

    public AppDbContext()
    {
    }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        builder.Entity<Service>()
               .Property(service => service.ID)
               .UseIdentityColumn(1, 1);
    } 

    public virtual DbSet<AppUser> AppUsers { get; set; }
    public virtual DbSet<Service> Services { get; set; }
}

If you notice that my DbContext class is inheriting from IdentityDbContext because I use identity.

The problem: I get this error:

CS0121
The call is ambiguous between the following methods or properties: 'Microsoft.EntityFrameworkCore.OraclePropertyBuilderExtensions.UseIdentityColumn(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder, int, int)' and 'Microsoft.EntityFrameworkCore.SqlServerPropertyBuilderExtensions.UseIdentityColumn(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder, int, int)'

Error Screenshot 1

Error Screenshot 2

Additional info

I reference another project in my solution this project will play the repository role, and he prepared to work with SQL Server, Oracle and MySQL.

The project I depend on is my own project, and it is open source that is the repository link

Please any help to fix this issue?

1 Answers

I guess you cannot just remove the one of two problematic using. Since those methods are extension methods (so static method) you could use them as static method :

Microsoft.EntityFrameworkCore.OraclePropertyBuilderExtensions.UseIdentityColumn(builder.Entity<Service>().Property(service => service.ID), 1, 1);

Or using static import :

using static Microsoft.EntityFrameworkCore.OraclePropertyBuilderExtensions;

Then

UseIdentityColumn(builder.Entity<Service>().Property(service => service.ID), 1, 1)

I know is not as beautiful as the fluent way of writing it but I don't think there is an alternative if you need all your using.

(I assumed you wanted to keep the Oracle one)

Related