Open Closed

Modular development with Abp Suite encountered an exception => The entity type 'ExtraPropertyDictionary' requires a primary key to be defined. #9317


User avatar
0
15021087273 created

Check the docs before asking a question: https://abp.io/docs/latest Check the samples to see the basic tasks: https://abp.io/docs/latest/samples The exact solution to your question may have been answered before, and please first use the search on the homepage.

Provide us with the following info: 🧐 Hint: If you are using the ABP Studio, you can see all the information about your solution from the configuration window, which opens when you right-click on the solution and click on the Solution Configuration button.

  • Template: app

  • Created ABP Studio Version: 0.9.26

  • Current ABP Studio Version: 0.9.26

  • Tiered: Yes

  • Multi-Tenancy: No

  • UI Framework: angular

  • Theme: leptonx

  • Theme Style: system

  • Theme Menu Placement: side

  • Run Install Libs: Yes

  • Progressive Web App: No

  • Run Progressive Web App Support: No

  • Database Provider: ef

  • Database Management System: postgresql

  • Separate Tenant Schema: No

  • Create Initial Migration: Yes

  • Run Db Migrator: Yes

  • Mobile Framework: maui

  • Public Website: Yes

  • Social Login: No

  • Include Tests: Yes

  • Kubernetes Configuration: Yes

  • Distributed Event Bus: rabbitmq

  • Use Local References: No

  • Optional Modules:

    • GDPR
    • FileManagement
    • TextTemplateManagement
    • LanguageManagement
    • AuditLogging
    • Chat
    • OpenIddictAdmin
  • Create Command: abp new AbpModularSolution1 -t app --tiered --ui-framework angular --mobile maui --database-provider ef --database-management-system postgresql --theme leptonx --public-website --without-cms-kit --dont-run-bundling --no-multi-tenancy --no-social-logins -no-saas -chat

  • Exception message and full stack trace: 1)Exception Screenshot:

2)full stack trace: System.InvalidOperationException HResult=0x80131509 Message=The entity type 'ExtraPropertyDictionary' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types, see https://go.microsoft.com/fwlink/?linkid=2141943. Source=Microsoft.EntityFrameworkCore StackTrace: 在 Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidateNonNullPrimaryKeys(IModel model, IDiagnosticsLogger1 logger) 在 Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger) 在 Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger) 在 Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal.NpgsqlModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger) 在 Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.Initialize(IModel model, Boolean designTime, IDiagnosticsLogger1 validationLogger) 在 Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime) 在 Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime) 在 Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel(Boolean designTime) 在 Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model() 在 Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__8_4(IServiceProvider p) 在 Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) 在 Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) 在 Volo.Abp.EntityFrameworkCore.AbpDbContextOptionsExtension.<>c__DisplayClass0_0.<ApplyServices>b__1(IServiceProvider provider) 在 Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType) 在 Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) 在 Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) 在 Microsoft.EntityFrameworkCore.DbContext.get_ContextServices() 在 Microsoft.EntityFrameworkCore.DbContext.get_ChangeTracker() 在 Volo.Abp.EntityFrameworkCore.AbpDbContext1.Initialize(AbpEfCoreDbContextInitializationContext initializationContext) 在 Volo.Abp.Uow.EntityFrameworkCore.UnitOfWorkDbContextProvider1.<CreateDbContextAsync>d__14.MoveNext() 在 Volo.Abp.Uow.EntityFrameworkCore.UnitOfWorkDbContextProvider1.d__12.MoveNext() 在 Volo.Abp.Domain.Repositories.EntityFrameworkCore.EfCoreRepository2.<GetDbSetAsync>d__10.MoveNext() 在 Abm.TestModule.Hellos.EfCoreHelloRepositoryBase.<GetQueryForNavigationPropertiesAsync>d__4.MoveNext() 在 D:\workspace\source\LaunchX Platform\TestSolutions\AbpModularSolution1\modules\abm.testmodule\src\Abm.TestModule.EntityFrameworkCore\Hellos\EfCoreHelloRepository.cs 中: 第 68 行 在 Abm.TestModule.Hellos.EfCoreHelloRepositoryBase.<GetCountAsync>d__7.MoveNext() 在 D:\workspace\source\LaunchX Platform\TestSolutions\AbpModularSolution1\modules\abm.testmodule\src\Abm.TestModule.EntityFrameworkCore\Hellos\EfCoreHelloRepository.cs 中: 第 113 行 在 Castle.DynamicProxy.AsyncInterceptorBase.<ProceedAsynchronous>d__141.MoveNext() 在 Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.<ProceedAsync>d__7.MoveNext() 在 Volo.Abp.Uow.UnitOfWorkInterceptor.<InterceptAsync>d__2.MoveNext() 在 Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.d__31.MoveNext() 在 Abm.TestModule.Hellos.HellosAppServiceBase.<GetListAsync>d__5.MoveNext() 在 D:\workspace\source\LaunchX Platform\TestSolutions\AbpModularSolution1\modules\abm.testmodule\src\Abm.TestModule.Application\Hellos\HellosAppService.cs 中: 第 45 行 在 Castle.DynamicProxy.AsyncInterceptorBase.<ProceedAsynchronous>d__141.MoveNext() 在 Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.<ProceedAsync>d__7.MoveNext() 在 Volo.Abp.GlobalFeatures.GlobalFeatureInterceptor.<InterceptAsync>d__0.MoveNext() 在 Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.d__31.MoveNext() 在 Castle.DynamicProxy.AsyncInterceptorBase.<ProceedAsynchronous>d__141.MoveNext() 在 Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.d__7.MoveNext() 在 Volo.Abp.Auditing.AuditingInterceptor.d__4.MoveNext()

  • Steps to reproduce the issue: Step 1: create Abp solution named AbpModularSolution1

Step 2: create folder named modules

Step 3: create DDD Module name Abm.TestModule under the modules folder

Step 4: Imports Volo.Abp.Identity.Pro(9.1.1)

Step 5: use abp suite to create a basic entity name Hello and Add properties ( Name & description)

Step 6: Add Navigation property(1-n) for Hello entity, I picked IdentityUserId from Volo.Abp.Identity and Click Save and generate.

Step 7: Import Abm.TestModule to AbpModularSolution1

Step 8: Add Migration and Update Database for EntityFrameworkCore package

Step 9: Start Redis & AbpModularSolution1.AuthServer & HttpApi.Host & Angular

Step 10. Login and Click TestModule>Hellos menu, the system turns error messages.


4 Answer(s)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    It seems it cannot configure entity base properties in DbContext or the extension method of the module.

    Can you check AbpModularSolution1DbContext and find OnModelCreating() method in it.

    Is there any method that configures your module something like ConfigureTestModule()

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            
            // ...
            
            builder.ConfigureTestModule(); // 👈
        }
    

    If yes, go to your module solution and find that ConfigureTestModule method and make sure your entity is configured properly and calls .ConfigureByConvention() method in entity builder.

    public static void ConfigureTestModule(this ModelBuilder builder)
    {
        // ...
    
        builder.Entity<Hello>(b =>
        {
            b.ToTable(TestModuleConsts.DbTablePrefix + "Books",
                TestModuleConsts.DbSchema);
                // 👇 Make sure this is called.
            b.ConfigureByConvention(); //auto configure for the base class props
        
        });
        
        // ...
    }
    

    This method configures ExtraPropertyDictionary to be kept as string as json in the databse and that exception will be gone

  • User Avatar
    0
    15021087273 created

    I followed your instructions to check the code and it meets the requirements. The following are two code blocks: 1)OnModelCreating

    [ConnectionStringName(TestModuleDbProperties.ConnectionStringName)]
    public class TestModuleDbContext : AbpDbContext<TestModuleDbContext>, ITestModuleDbContext
    {
        public DbSet<Hello> Hellos { get; set; } = null!;
        /* Add DbSet for each Aggregate Root here. Example:
         * public DbSet<Question> Questions { get; set; }
         */
    
        public TestModuleDbContext(DbContextOptions<TestModuleDbContext> options)
            : base(options)
        {
    
        }
    
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
    
            builder.ConfigureTestModule();
        }
    }
    

    2)ConfigureTestModule

    public static class TestModuleDbContextModelCreatingExtensions
    {
        public static void ConfigureTestModule(
            this ModelBuilder builder)
        {
            Check.NotNull(builder, nameof(builder));
    
            /* Configure all entities here. Example:
    
            builder.Entity<Question>(b =>
            {
                //Configure table & schema name
                b.ToTable(TestModuleDbProperties.DbTablePrefix + "Questions", TestModuleDbProperties.DbSchema);
    
                b.ConfigureByConvention();
    
                //Properties
                b.Property(q => q.Title).IsRequired().HasMaxLength(QuestionConsts.MaxTitleLength);
    
                //Relations
                b.HasMany(question => question.Tags).WithOne().HasForeignKey(qt => qt.QuestionId);
    
                //Indexes
                b.HasIndex(q => q.CreationTime);
            });
            */
            if (builder.IsHostDatabase())
            {
    
            }
            if (builder.IsHostDatabase())
            {
                builder.Entity<Hello>(b =>
                {
                    b.ToTable(TestModuleDbProperties.DbTablePrefix + "Hellos", TestModuleDbProperties.DbSchema);
                    b.ConfigureByConvention();
                    b.Property(x => x.Name).HasColumnName(nameof(Hello.Name)).IsRequired().HasMaxLength(HelloConsts.NameMaxLength);
                    b.Property(x => x.Description).HasColumnName(nameof(Hello.Description));
                    b.HasOne<IdentityUser>().WithMany().IsRequired().HasForeignKey(x => x.IdentityUserId).OnDelete(DeleteBehavior.NoAction);
                });
    
            }
        }
    }
    

    Is it caused by the development environment? My Abp Suite version is v9.1.1

  • User Avatar
    0
    15021087273 created

    AbpModularSolution1DbContext Code:

    [ReplaceDbContext(typeof(IIdentityProDbContext))]
    [ConnectionStringName("Default")]
    public class AbpModularSolution1DbContext :
        AbpDbContext<AbpModularSolution1DbContext>,
        IIdentityProDbContext
    {
        /* Add DbSet properties for your Aggregate Roots / Entities here. */
    
    
        #region Entities from the modules
    
        /* Notice: We only implemented IIdentityProDbContext 
         * and replaced them for this DbContext. This allows you to perform JOIN
         * queries for the entities of these modules over the repositories easily. You
         * typically don't need that for other modules. But, if you need, you can
         * implement the DbContext interface of the needed module and use ReplaceDbContext
         * attribute just like IIdentityProDbContext .
         *
         * More info: Replacing a DbContext of a module ensures that the related module
         * uses this DbContext on runtime. Otherwise, it will use its own DbContext class.
         */
    
        // Identity
        public DbSet<IdentityUser> Users { get; set; }
        public DbSet<IdentityRole> Roles { get; set; }
        public DbSet<IdentityClaimType> ClaimTypes { get; set; }
        public DbSet<OrganizationUnit> OrganizationUnits { get; set; }
        public DbSet<IdentitySecurityLog> SecurityLogs { get; set; }
        public DbSet<IdentityLinkUser> LinkUsers { get; set; }
        public DbSet<IdentityUserDelegation> UserDelegations { get; set; }
        public DbSet<IdentitySession> Sessions { get; set; }
    
        #endregion
    
        public AbpModularSolution1DbContext(DbContextOptions<AbpModularSolution1DbContext> options)
            : base(options)
        {
    
        }
    
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
    
            builder.ConfigureTestModule();
    
            /* Include modules to your migration db context */
    
            builder.ConfigurePermissionManagement();
            builder.ConfigureSettingManagement();
            builder.ConfigureBackgroundJobs();
            builder.ConfigureAuditLogging();
            builder.ConfigureFeatureManagement();
            builder.ConfigureIdentityPro();
            builder.ConfigureOpenIddictPro();
            builder.ConfigureLanguageManagement();
            builder.ConfigureFileManagement();
            builder.ConfigureChat();
            builder.ConfigureTextTemplateManagement();
            builder.ConfigureGdpr();
            builder.ConfigureBlobStoring();
            
            /* Configure your own tables/entities inside here */
    
            //builder.Entity<YourEntity>(b =>
            //{
            //    b.ToTable(AbpModularSolution1Consts.DbTablePrefix + "YourEntities", AbpModularSolution1Consts.DbSchema);
            //    b.ConfigureByConvention(); //auto configure for the base class props
            //    //...
            //});
        }
    }
    
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Whenever you create a new project there'll be already a file for that purpose with an example:

    • For Module extension:

    • And Entity extension: (if you choosed EntityFrameworkCore)


    You can uncomment that examnples and ready to go, there'll be no other changes. If you configured any EntityExtension, you'll need to create a database migration.

    If you are not familiar with CLI commands you can do it in ABP Studio UI:

    And that's it you'll see the new migration:

    • Run .DbMigrator project

    • Run .Web project

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on June 13, 2025, 11:37