Open Closed

ExtraPropertyDictionary issues when trying to add OrganizationUnit as a Foreign key in a Module #6552


User avatar
0
HaydenFerries created

I am having issues trying to add a OrganizationUnit as a Foreign Key to one of my Entities. I am building a Module and have generated everything using ABP Suite, so the AuthServer and the HttpApi.Host are separate and within the Host.

I was originally getting this same error when trying to create migrations for HttpApi.Host but resolved this by adding modelBuilder.ConfigureIdentity(); into the HttpApiHostMigrationsDbContext so that it would add all the required tables to the database.

I am now getting this error when trying to Access any table via HttpApi request from Angular.

I have deleted and regenerated all the Migrations and Database to no avail. I feel like I am missing one small thing to make this work but can't for the life of me figure out what that is.

Here is one of the Entities I am trying to link OrganizationUnits to: `using System; using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy;

namespace enform.envolve.crm.AccountAccesses { public class AccountAccess : FullAuditedAggregateRoot

    public Guid AccountId { get; protected set; }
    public Guid OrganizationUnitsId { get; protected set; }
    
    private AccountAccess()
    {

    }

    public AccountAccess(Guid id, Guid accountId, Guid organizationUnitsId)
    {
        Id = id;
        AccountId = accountId;
        OrganizationUnitsId = organizationUnitsId;
    }
}

}

    builder.Entity<AccountAccess>(b =>
    {
        b.ToTable(crmDbProperties.DbTablePrefix + "AccountAccess", crmDbProperties.DbSchema);
        b.ConfigureByConvention();
        b.Property(x => x.TenantId).HasColumnName(nameof(Account.TenantId));
        b.HasOne<Account>().WithMany(x => x.OrganisationUnitAccesses).HasForeignKey(x => x.AccountId).IsRequired()
            .OnDelete(DeleteBehavior.NoAction);
        b.HasOne<OrganizationUnit>().WithMany().HasForeignKey(x => x.OrganizationUnitsId).IsRequired()
            .OnDelete(DeleteBehavior.NoAction);
    });

`

  • ABP Framework version: v7.4.2
  • UI Type: Angular
  • Database System: EF Core SQL Server
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace: [10:45:37 ERR] 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 ResolveService(ILEmitResolverBuilderRuntimeContext, ServiceProviderEngineScope) at ResolveService(ILEmitResolverBuilderRuntimeContext, ServiceProviderEngineScope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope 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_DbContextDependencies() at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices() at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider() 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 enform.envolve.crm.Genders.EfCoreGenderRepositoryBase.GetCountAsync(String filterText, String code, String name, CancellationToken cancellationToken) in C:\Users\HaydenFerries\source\repos\Envolve\enform.envolve.crm\src\enform.envolve.crm.EntityFrameworkCore\Genders\EfCoreGenderRepository.cs:line 42 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.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at enform.envolve.crm.Genders.GendersAppServiceBase.GetListAsync(GetGendersInput input) in C:\Users\HaydenFerries\source\repos\Envolve\enform.envolve.crm\src\enform.envolve.crm.Application\Genders\GendersAppService.cs:line 40 at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() at Volo.Abp.GlobalFeatures.GlobalFeatureInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() at Volo.Abp.Authorization.AuthorizationInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() at Volo.Abp.Auditing.AuditingInterceptor.ProceedByLoggingAsync(IAbpMethodInvocation invocation, AbpAuditingOptions options, IAuditingHelper auditingHelper, IAuditLogScope auditLogScope) at Volo.Abp.Auditing.AuditingInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) 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.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed) at lambda_method2036(Closure, Object) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.
  • Steps to reproduce the issue:
  • Create new Module (Angular) using ABP suite
  • Add Table that has a OrganizationUnit as a Foreign Key
  • Add Migrations and try to run Angular to access the table via API call

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Steps to reproduce the issue: Create new Module (Angular) using ABP suite Add Table that has a OrganizationUnit as a Foreign Key Add Migrations and try to run Angular to access the table via API call

    Can you share this project to liming.ma@volosoft.com ?

    Thanks.

  • User Avatar
    0
    HaydenFerries created

    I have added you as a collaborator to my Git Project OrgUnitTest

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You need to replace IIdentityDbContext with YourDbcontext to relationship with OrganizationUnit

    You are using Identity and Identity Pro at same time. Please use Identity Pro instead of Identity

    https://github.com/HaydenFerries/OrgUnitTest/pull/1

    https://github.com/HaydenFerries/OrgUnitTest/blob/e1126389078fa9a79f5b1aa2ce69065f7307c415/src/OrgUnitTest.EntityFrameworkCore/EntityFrameworkCore/OrgUnitTestEntityFrameworkCoreModule.cs#L28

    https://github.com/HaydenFerries/OrgUnitTest/blob/e1126389078fa9a79f5b1aa2ce69065f7307c415/src/OrgUnitTest.EntityFrameworkCore/EntityFrameworkCore/OrgUnitTestDbContextModelCreatingExtensions.cs#L16

    https://github.com/HaydenFerries/OrgUnitTest/blob/e1126389078fa9a79f5b1aa2ce69065f7307c415/src/OrgUnitTest.EntityFrameworkCore/EntityFrameworkCore/IOrgUnitTestDbContext.cs#L11

    https://github.com/HaydenFerries/OrgUnitTest/blob/e1126389078fa9a79f5b1aa2ce69065f7307c415/src/OrgUnitTest.EntityFrameworkCore/EntityFrameworkCore/OrgUnitTestDbContext.cs#L15-L22

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11