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<OrganizationUnitDto>(organizationUnit);
}
I passed the TypeId, but the OrganizationUnit constructor only takes three parameters. How can I solve this issue?
4 Answer(s)
-
0
Hi @ismcagdas , Any update regarding this issue? Could you please check as soon as possible?
-
0
Hi,
You can't pass
TypeId
to OrganizationUnit. You need to createMyOrganizationUnit
class. So, you also need to create a copy ofOrganizationUnitManager
which should useMyOrganizationUnit
. -
0
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.SingleQueryingEnumerable
1.AsyncEnumerator.MoveNextAsync() at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable
1 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, ValueTask
1 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.
-
0
Hi,
You can try filling
Discriminator
column with the value OrganizationUnit for existing records and try again.