0
alfar_re created
Hi,
Is it possible to return the just created row? Like on the following method...I'd like to get the Id of the just created chartOfAccount as below.
protected virtual async Task Create(CreateOrEditChartOfAccountDto input)
{
var chartOfAccount = ObjectMapper.Map<ChartOfAccount>(input);
if (AbpSession.TenantId != null)
{
chartOfAccount.TenantId = (int)AbpSession.TenantId;
}
await _chartOfAccountRepository.InsertAsync(chartOfAccount);
}
Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)
6 Answer(s)
-
0
hi
Try
var id = await _chartOfAccountRepository.InsertAndGetId(chartOfAccount);Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
This is the result...
System.NullReferenceException: Object reference not set to an instance of an object. at reos.ChartOfAccounts.ChartOfAccountsAppService.Create(CreateOrEditChartOfAccountDto input) in D:\OneDrive\Projects\reos\src\reos.Application\ChartOfAccounts\ChartOfAccountsAppService.cs:line 137 at Abp.Threading.InternalAsyncHelper.AwaitTaskWithPostActionAndFinally(Task actualReturnValue, Func1 postAction, Action1 finalAction) at reos.ChartOfAccounts.ChartOfAccountsAppService.CreateOrEdit(CreateOrEditChartOfAccountDto input) in D:\OneDrive\Projects\reos\src\reos.Application\ChartOfAccounts\ChartOfAccountsAppService.cs:line 115 at lambda_method(Closure , Object ) at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult() at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableResultExecutor.Execute(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)Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
hi alfar_re
Can you share the complete code of the
ChartOfAccountsAppService.Createmethod?Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @maliming,
Here you go
[AbpAuthorize(AppPermissions.Pages_ChartOfAccounts_Create)] protected virtual async Task Create(CreateOrEditChartOfAccountDto input) { var chartOfAccount = ObjectMapper.Map<ChartOfAccount>(input); if (AbpSession.TenantId != null) { chartOfAccount.TenantId = (int)AbpSession.TenantId; } //await _chartOfAccountRepository.InsertAsync(chartOfAccount); var id = await _chartOfAccountRepository.InsertAndGetIdAsync(chartOfAccount); }Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
The method looks fine, can you debug to see which object is null?
System.NullReferenceException: Object reference not set to an instance of an object. at reos.ChartOfAccounts.ChartOfAccountsAppService.Create(CreateOrEditChartOfAccountDto input) in D:\OneDrive\Projects\reos\src\reos.Application\ChartOfAccounts\ChartOfAccountsAppService.cs:line 137
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi,
I actually got it working. Thank you for your pointers.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)