System.MissingMethodException:找不到方法:'System.Type Microsoft.EntityFrameworkCore.Metadata.ITypeBase.get_ClrType()'

cke*_*dee 9 c# asp.net entity-framework-core aspnetboilerplate .net-5

Good Day Developers,
Please I updated my .Net5 to .Net6 and I have this errors on adding migration:
Run Code Online (Sandbox Code Playgroud)

System.MissingMethodException:找不到方法:“System.Type Microsoft.EntityFrameworkCore.Metadata.ITypeBase.get_ClrType()”。在 Abp.EntityFrameworkCore.AbpDbContext.OnModelCreating(ModelBuilder modelBuilder) 在 Abp.Zero.EntityFrameworkCore.AbpZeroCommonDbContext 3.OnModelCreating(ModelBuilder modelBuilder) at Abp.Zero.EntityFrameworkCore.AbpZeroDbContext4.OnModelCreating(ModelBuilder modelBuilder) 在 Microsoft.EntityFrameworkCore.Infrastruct.ModelCustomizer.Customize(ModelBuilder modelBuilder, DbContext context) 在 Microsoft.EntityFrameworkCore.Infrastruct .ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, ModelDependencies modelDependencies) 在 Microsoft.EntityFrameworkCore.Infrastruct.ModelSource.GetModel(DbContext context, ModelCreationDependency modelCreationDependencies, Boolean designTime) 在 Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel(Boolean designTime) 在 Microsoft .EntityFrameworkCore.Internal.DbContextServices.get_Model() 在 Microsoft.EntityFrameworkCore.Infrastruct.EntityFrameworkServicesBuilder.<>c.b__8_4(IServiceProvider p) 在 Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor 2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument 参数) 在 Microsoft .Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite,RuntimeResolverContext context)位于 Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite,TArgument 参数)位于 Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolv呃.VisitCache (ServiceCallSite callSite、RuntimeResolverContext 上下文、ServiceProviderEngineScope serviceProviderEngine、RuntimeResolverLock lockType)位于 Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCacMicrosoft.EntityFrameworkCore.Metadata.ITypeBase.get_ClrType()'。

我检查了所有 microsoft.entityFrameworkcore 包,它们的版本相同。 指向我的代码的这个版本,

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

            modelBuilder.Entity<BinaryObject>(b =>
            {
                b.HasIndex(e => new { e.TenantId });
            });

            modelBuilder.Entity<ChatMessage>(b =>
            {
                b.HasIndex(e => new { e.TenantId, e.UserId, e.ReadState });
                b.HasIndex(e => new { e.TenantId, e.TargetUserId, e.ReadState });
                b.HasIndex(e => new { e.TargetTenantId, e.TargetUserId, e.ReadState });
                b.HasIndex(e => new { e.TargetTenantId, e.UserId, e.ReadState });
            });

            modelBuilder.Entity<Friendship>(b =>
            {
                b.HasIndex(e => new { e.TenantId, e.UserId });
                b.HasIndex(e => new { e.TenantId, e.FriendUserId });
                b.HasIndex(e => new { e.FriendTenantId, e.UserId });
                b.HasIndex(e => new { e.FriendTenantId, e.FriendUserId });
            });

            modelBuilder.Entity<Tenant>(b =>
            {
                b.HasIndex(e => new { e.SubscriptionEndDateUtc });
                b.HasIndex(e => new { e.CreationTime });
            });

            modelBuilder.Entity<SubscriptionPayment>(b =>
            {
                b.HasIndex(e => new { e.Status, e.CreationTime });
                b.HasIndex(e => new { PaymentId = e.ExternalPaymentId, e.Gateway });
            });

            modelBuilder.Entity<SubscriptionPaymentExtensionData>(b =>
            {
                b.HasQueryFilter(m => !m.IsDeleted)
                    .HasIndex(e => new { e.SubscriptionPaymentId, e.Key, e.IsDeleted })
                    .IsUnique();
            });

            modelBuilder.Entity<UserDelegation>(b =>
            {
                b.HasIndex(e => new { e.TenantId, e.SourceUserId });
                b.HasIndex(e => new { e.TenantId, e.TargetUserId });
            });

            modelBuilder.ConfigurePersistedGrantEntity();
        }
Run Code Online (Sandbox Code Playgroud)

我可以实施什么来解决这个问题吗? 拜托,我需要帮助

小智 16

当您的项目中有不同版本的EntityFrameworkCore和时NetCore,就会出现此错误,请务必安装EntityFramework与您的版本兼容的NetCore版本。

对于NET 5.0包是:

Microsoft.EntityFrameworkCore.Design [5.0.10]
Microsoft.EntityFrameworkCore.SqlServer [5.0.10]
Microsoft.EntityFrameworkCore.Tools [5.0.10]

您可以NET 6.0安装:

Microsoft.EntityFrameworkCore.Design [6.0.10]
Microsoft.EntityFrameworkCore.SqlServer [6.0.10]
Microsoft.EntityFrameworkCore.Tools [6.0.10]

  • 我从 6.0 升级到 7.0 时遇到了这个问题。除此之外,请确保您还升级了“EFCore.NamingConventions”包(如果您正在使用它):) (2认同)