以下方法或属性之间的调用不明确 [Entity Framework Core] [OnModelCreating]

DEV*_*DEV 3 c# dbcontext asp.net-identity entity-framework-core

我使用 EF Core,在我的dbcontext类中,我重写了将onModelCreating类中的一个属性配置为在 SQL Server 中自动递增的方法。

这是我的DbContext课:

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; }
}
Run Code Online (Sandbox Code Playgroud)

如果您注意到我的DbContext类继承自IdentityDbContext,因为我使用了身份。

问题:我收到此错误:

CS0121
以下方法或属性之间的调用不明确:“Microsoft.EntityFrameworkCore.OraclePropertyBuilderExtensions.UseIdentityColumn(Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder, int, int)”和“Microsoft.EntityFrameworkCore.SqlServerPropertyBuilderExtensions.UseIdentityColumn(Microsoft.EntityFrameworkCore. Metadata.Builders.PropertyBuilder,int,int)'

错误截图1

错误截图2

附加信息

我在我的解决方案中引用了另一个项目,这个项目将扮演存储库的角色,他准备与SQL Server、Oracle和MySQL一起工作。

我依赖的项目是我自己的项目,而且是开源的就是仓库链接

请帮忙解决这个问题吗?

Arc*_*ord 5

我想你不能只删除两个有问题的使用之一。由于这些方法是扩展方法(静态方法),您可以将它们用作静态方法:

Microsoft.EntityFrameworkCore.OraclePropertyBuilderExtensions.UseIdentityColumn(builder.Entity<Service>().Property(service => service.ID), 1, 1);
Run Code Online (Sandbox Code Playgroud)

或者使用静态导入:

using static Microsoft.EntityFrameworkCore.OraclePropertyBuilderExtensions;
Run Code Online (Sandbox Code Playgroud)

然后

UseIdentityColumn(builder.Entity<Service>().Property(service => service.ID), 1, 1)
Run Code Online (Sandbox Code Playgroud)

我知道它不如流畅的书写方式那么漂亮,但如果您需要全部使用,我认为没有其他选择。

(我以为你想保留 Oracle 的)