Docs checked:
https://abp.io/docs/latest
https://abp.io/docs/latest/samples
Searched ABP homepage & GitHub issues (including issue #9602 and related threads)
๐งฉ Problem Summary
I am getting the following EF Core runtime error when navigating to a page that queries a custom module entity:
The entity type ExtraPropertyDictionary requires a primary key to be defined. If you intended to use a keyless entity type, call HasNoKey in OnModelCreating.
This occurs during runtime DbContext model initialization (first repository access), not during migrations.
The entity in question inherits from FullAuditedAggregateRoot<Guid> and does not explicitly define or map ExtraPropertyDictionary.
๐งช Environment
ABP version: 10.0.1 (Commercial / Pro)
Created with: ABP Studio
Architecture:
Tiered solution
Modular (apps + modules folder structure)
Database: SQL Server
ORM: EF Core
Identity: ABP Identity / Identity Pro
Frontend: Angular
๐ฅ Exception message and full stack trace 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.
System.InvalidOperationException: The entity type 'ExtraPropertyDictionary' requires a primary key to be defined.
at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidateNonNullPrimaryKeys(IModel model, ...)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(...)
...
at Volo.Abp.EntityFrameworkCore.AbpDbContext1.Initialize(...) at Volo.Abp.Domain.Repositories.EntityFrameworkCore.EfCoreRepository2.GetDbSetAsync()
at Acs.PrincipalGraph.Principals.EfCorePrincipalRepository.GetQueryForNavigationPropertiesAsync()
at Acs.PrincipalGraph.Principals.PrincipalsAppService.GetListAsync(...)
๐งฌ Entity Definition public abstract class PrincipalBase : FullAuditedAggregateRoot<Guid>, IMultiTenant { public Guid? TenantId { get; set; }
public PrincipalKind Kind { get; set; }
public PrincipalScope Scope { get; set; }
public string? ExternalId { get; set; }
public string? DisplayName { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
public bool IsActive { get; set; }
public Guid? UserId { get; set; }
}
ExtraProperties and ConcurrencyStamp are inherited from FullAuditedAggregateRoot
I did not define ExtraPropertyDictionary anywhere in my code
๐ Module EF Core Mapping public static void ConfigurePrincipalGraph(this ModelBuilder builder) { builder.Entity<Principal>(b => { b.ToTable("AcsPrincipals"); b.ConfigureByConvention();
b.Property(x => x.ExternalId).HasMaxLength(512);
b.Property(x => x.DisplayName).HasMaxLength(128);
b.Property(x => x.FirstName).HasMaxLength(128);
b.Property(x => x.LastName).HasMaxLength(128);
b.HasOne<IdentityUser>()
.WithMany()
.HasForeignKey(x => x.UserId)
.OnDelete(DeleteBehavior.SetNull);
});
}
๐งฑ Runtime DbContext OnModelCreating protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder);
builder.ConfigurePermissionManagement();
builder.ConfigureSettingManagement();
builder.ConfigureBackgroundJobs();
builder.ConfigureAuditLogging();
builder.ConfigureFeatureManagement();
builder.ConfigureIdentityPro();
builder.ConfigureOpenIddictPro();
builder.ConfigureLanguageManagement();
builder.ConfigureSaas();
builder.ConfigureTextTemplateManagement();
builder.ConfigureGdpr();
builder.ConfigureCmsKit();
builder.ConfigureCmsKitPro();
builder.ConfigureBlobStoring();
builder.ConfigureFoundation();
builder.ConfigurePrincipalGraph();
}
๐ Steps to Reproduce
Create a new ABP 10.0.1 solution using ABP Studio (tiered, modular).
Create a custom module.
Add an entity inheriting from FullAuditedAggregateRoot<Guid>.
Add EF Core mapping using ConfigureByConvention().
Reference IdentityUser with a FK (HasOne<IdentityUser>()).
Run the application.
Navigate to a page that queries the entity via an EF Core repository.
โก๏ธ Runtime throws ExtraPropertyDictionary requires a primary key.
โ What Iโm Trying to Understand
Is this a missing or new required configuration in ABP 10.x for modular DbContexts?
Should ConfigureObjectExtensions() be required explicitly in runtime DbContexts?
Is there an ordering requirement between:
ConfigureObjectExtensions
ConfigureIdentity / ConfigureIdentityPro
custom module mappings?
Is there a recommended pattern when custom modules reference IdentityUser and use audited aggregate roots?
I expected FullAuditedAggregateRoot + ConfigureByConvention() to be sufficient, as in earlier ABP versions.
โ What Iโve Already Tried
Removing the IdentityUser relationship (error still occurs)
Verifying no DbSet<ExtraPropertyDictionary> exists
Verifying no explicit modelBuilder.Entity<ExtraPropertyDictionary>()
Comparing with GitHub issue #9602 and similar threads
1 Answer(s)
-
0
I removed project references made to <PackageReference Include="Volo.Abp.Identity.Pro.Application.Contracts" Version="10.0.1" /> <PackageReference Include="Volo.Abp.Identity.Pro.Domain" Version="10.0.1" /> from the corresponding DDD module project and removed reference made to IdentityUser and the issue no longer occurs