Open Closed

We started getting exception related to ExtraPropertyDictionary from entity that doesn't have extra properties. #8659


User avatar
0
JanneHarju created
  • ABP Framework version: v8.2.1
  • UI Type: Angular
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): separate
  • 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. 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. at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.ValidateNonNullPrimaryKeys(IModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal.SqlServerModelValidator.Validate(IModel model, IDiagnosticsLogger1 logger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.Initialize(IModel model, Boolean designTime, IDiagnosticsLogger1 validationLogger) at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime) at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel(Boolean designTime) at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model() at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__8_4(IServiceProvider p) at ResolveService(ILEmitResolverBuilderRuntimeContext, ServiceProviderEngineScope) at ResolveService(ILEmitResolverBuilderRuntimeContext, ServiceProviderEngineScope) at ResolveService(ILEmitResolverBuilderRuntimeContext, ServiceProviderEngineScope) at ResolveService(ILEmitResolverBuilderRuntimeContext, ServiceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.EntityFrameworkCore.DbContext.get_ChangeTracker() at Volo.Abp.EntityFrameworkCore.AbpDbContext1.Initialize(AbpEfCoreDbContextInitializationContext initializationContext) at Volo.Abp.Uow.EntityFrameworkCore.UnitOfWorkDbContextProvider1.CreateDbContextAsync(IUnitOfWork unitOfWork, String connectionStringName, String connectionString) at Volo.Abp.Uow.EntityFrameworkCore.UnitOfWorkDbContextProvider1.GetDbContextAsync() at Volo.Abp.Domain.Repositories.EntityFrameworkCore.EfCoreRepository2.GetDbSetAsync() at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.Dyn2025-01-16 13:12:43.260 +02:00 [INF] Loaded ABP modules:
  • Steps to reproduce the issue: I managed to find that this exception is thrown from these lines at our background process manager:
_mLOutputStorageService.ConnectToOutputStorage();
string currentTenantName = _currentTenant.Name!;
IList<BaselineDemandForecast> baselineDemandForecasts = await _mLOutputStorageService.DownloadForecastDataAsync(currentTenantName);
//remove all old forecasts from same run and insert new ones
var newRunIdFromDownloadedData = baselineDemandForecasts[0]?.RunId;
var query = await _baselineDemandForecastRepository.GetQueryableAsync();
var oldForecasts = query.Where(x => x.RunId == newRunIdFromDownloadedData);
await _baselineDemandForecastRepository.DeleteFromQueryAsync(oldForecasts);
foreach (var item in baselineDemandForecasts)
{
item.TenantId = _currentTenant.Id;
}
await _sqlBulkOperationsBaselineDemandForecastRepository.BulkInsert(baselineDemandForecasts);

and spesific line is: var query = await _baselineDemandForecastRepository.GetQueryableAsync();

Weird thing is that I haven't touched this part of code. I have some changes is in some Repositories. Here is original code from there. public EfCoreCalculatedSeasonalityProfileRepository(IDbContextProvider<ForecastingDbContext> dbContextProvider) and we changed to use interface like this: public EfCoreCalculatedSeasonalityProfileRepository(IDbContextProvider<IForecastingDbContext> dbContextProvider) but changes were into different repositories than what I'm using where probelm seems to be.

I found that in some other your customers have same kind of issues that they were missing module dependeces but I didn't found samekind of deficiencies in our code.

Here is definiton of that entity: public class BaselineDemandForecast : Entity<Guid>, IMultiTenant And here is builder configuration:

public class BaselineDemandForecastModelCreatingExtensions : IModuleEntityTypeConfiguration<BaselineDemandForecast>
{
    public bool IsApplicationDbContext { get; set; }
    public bool IsSqlite { get; set; }
    
    public void Configure(EntityTypeBuilder<BaselineDemandForecast> builder)
    {
        builder.ToTable(ForecastingDbProperties.DbTablePrefix + "BaselineDemandForecasts", ForecastingDbProperties.DbSchema);
        builder.ConfigureByConvention();
        builder.ConfigureByConventionSCM(IsSqlite);
        //here is ton of field definitions.
    }
}

Now I made test what is running this part of code. I only mock MLOutputStorageService to give me spesific list of items. And no exception.

Any idea what could be creating this issue?


1 Answer(s)
  • User Avatar
    0
    JanneHarju created

    Collegue found that these were needed although we were not doing over module joins. [ReplaceDbContext(typeof(IForecastingDbContext))] and

    modelBuilder.ConfigureForecasting();

    So after all it was same problem as others have. I didn't just remember that our background process manager has own db context.

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