Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

AbpOrganizationUnits add a new column to the existing table #12058


User avatar
0
[email protected] created

I have created a new class and added a new column as shown below:

public class MyOrganizationUnit : OrganizationUnit {~~~~ public long? TypeId { get; set; } public DynamicPropertyValue Type { get; set; }

}

Then, I added the entity to the DbContext, created a migration, and updated the database without any issues. However, an issue occurred during the CreateOrUpdate operation. I need to add the TypeId field to CreateOrganizationUnitInput.

Here is the API method:

public async Task<OrganizationUnitDto> CreateOrganizationUnit(CreateOrganizationUnitInput input) { var organizationUnit = new OrganizationUnit(AbpSession.TenantId, input.DisplayName, input.ParentId,input.TypeId);

 await _organizationUnitManager.CreateAsync(organizationUnit);
 await CurrentUnitOfWork.SaveChangesAsync();

 return ObjectMapper.Map&lt;OrganizationUnitDto&gt;(organizationUnit);

}

I passed the TypeId, but the OrganizationUnit constructor only takes three parameters. How can I solve this issue?


4 Answer(s)
  • User Avatar
    0
    [email protected] created

    Hi @ismcagdas , Any update regarding this issue? Could you please check as soon as possible?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can't pass TypeId to OrganizationUnit. You need to create MyOrganizationUnit class. So, you also need to create a copy of OrganizationUnitManager which should use MyOrganizationUnit.

  • User Avatar
    0
    [email protected] created

    Hi @ismcagdas,

    GetOrganizationUnits method get below error after Migration and Update Database.

    System.InvalidOperationException: Unable to materialize entity instance of type 'OrganizationUnit'. No discriminators matched the discriminator value ''. at lambda_method2946(Closure, QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator) at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable1.AsyncEnumerator.MoveNextAsync() at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at Intelly.Organizations.OrganizationUnitAppService.GetOrganizationUnits() in C:\Intelly_Dynamic_BE\Intelly_Dynamic_BE\src\Intelly.Application\Organizations\OrganizationUnitAppService.cs:line 116 at lambda_method2936(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.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

    how to solve this issue.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can try filling Discriminator column with the value OrganizationUnit for existing records and try again.