We're able to create an entity using the POST request, but however when use the GET request to GET the entity using the below code in the appservice, we're getting 404 error:
{ "error": { "code": null, "message": "There is no entity [EntityName] with id = 198ef20c-...!", "details": null, "data": null, "validationErrors": null } }
The id requested is the id that we obtained from Swagger response when we made the POST request. The same record is available in the DB as we can see it through SSMS.
EntityNameAppService.cs
public async Task<EntityNameDto> GetAsync(Guid id) { var entityName = await _entityNameRepository.GetAsync(id, true); return ObjectMapper.Map<EntityName, EntityNameDto>(entityName); }
Below is logs:
{
"code": null,
"message": "There is no entity EntityName with id = 198ef20c-...!",
"details": null,
"data": null,
"validationErrors": null
}
2021-09-26 12:56:45.431 +04:00 [ERR] There is no such an entity. Entity type: ZW.ProjectName.EntityNames.EntityName, id: 198ef20c-...
Volo.Abp.Domain.Entities.EntityNotFoundException: There is no such an entity. Entity type: ZW.ProjectName.EntityNames.EntityName, id: 198ef20c-...
at Volo.Abp.Domain.Repositories.EntityFrameworkCore.EfCoreRepository`3.GetAsync(TKey id, Boolean includeDetails, CancellationToken cancellationToken)
at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
at ZW.ProjectName.EntityNames.EntityNameAppService.GetAsync(Guid id) in D:\Workspace\ProjectName\aspnet-core\src\ZW.ProjectName.Application\EntityNames\EntityNameAppService.cs:line 110
at lambda_method2484(Closure , Object )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.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)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
2021-09-26 12:56:45.496 +04:00 [INF] Executing ObjectResult, writing value of type 'Volo.Abp.Http.RemoteServiceErrorResponse'.
2021-09-26 12:56:45.513 +04:00 [INF] Executed action ZW.ProjectName.EntityNames.EntityNameAppService.GetAsync (ZW.ProjectName.Application) in 5217.3693ms
2021-09-26 12:56:45.514 +04:00 [INF] Executed endpoint 'ZW.ProjectName.EntityNames.EntityNameAppService.GetAsync (ZW.ProjectName.Application)'
- ABP Framework version: v4.4.2
- UI type: swagger
- DB provider: EF Core
15 Answer(s)
-
0
hi Neozzz
Can you share a simple project to reproduce? liming.ma@volosoft.com
-
0
Hi maliming,
I've sent you a request to the repo on github.
Thank you
-
0
-
0
Hi maliming,
thank you for the help. We're able to retrieve the record now, the issue with tenant id was causing the problem. But there are 3 ICollections of 3 entities inside the entity type we're retrieving. We're able to POST the data and data is written into respective tables however when we use the below code to retrieve the record using GET:
public async Task<EntityNameDto> GetAsync(Guid id) { var entityName = await _entityNameRepository.GetAsync(id); return ObjectMapper.Map<EntityName, EntityNameDto>(entityName); }
The collections are shown empty as below:
"contacts": [], "addresses": [], "roles": [],
I can show it with sample data if you could remote?
Thanks a lot.
-
0
Hi
You should configure the
Include
of your EF Core Repository.https://docs.abp.io/en/abp/4.4/Entity-Framework-Core#eager-loading-load-with-details
https://github.com/abpframework/abp/blob/dev/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/IdentityEfCoreQueryableExtensions.cs#L8
https://github.com/abpframework/abp/blob/dev/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs#L273
-
0
Hi maliming,
Thank you for the reply. I was able to obtain 1 level of relationship using the following code:
public async Task<EntityTypeDto> GetExtendedAsync(Guid id) { //eager loading var queryable = await _entityTypeRepository.WithDetailsAsync(x => x.Contacts, x => x.Addresses, x => x.Roles); var query = queryable.Where(x => x.Id == id); var entityType = await AsyncExecuter.FirstOrDefaultAsync(query); return ObjectMapper.Map<EntityType, EntityTypeDto>(entityType); }
How to drill down into another level of relationships within Contacts to obtain collection of PhoneNumbers like below:
var entityName = context.EntityNames .Include(entityName => entityName.Contacts) .ThenInclude(contact => contact.PhoneNumbers) .ToList();
-
0
hi Neozzz
Did you add the IncludeDetails extension method?
-
0
Hi maliming,
Should I use WithDetailsAsync as well along with it or this is separate?
TY
-
0
hi
You should add the
IncludeDetails
and use it inincludeDetails
. -
0
Hi, I did the following:
created
EfCoreEntityTypeQueryableExtension
with the following code:public static IQueryable<EntityType> IncludeDetails(this IQueryable<EntityType> queryable, bool include = true) { if (!include) { return queryable; } return queryable.Include(et => et.Contacts) .ThenInclude(ec => ec.PhoneNumbers) .Include(et => et.Contacts) .ThenInclude(ec => ec.FaxNumbers); }
Then wrote the following in
EfCoreEntityTypeRepository
:public override async Task<IQueryable<EntityType>> WithDetailsAsync() { return (await GetQueryableAsync()).IncludeDetails(); }
This still doesn't populate the data retrieved. Is there anywhere else I have to check?
Thank you :)
-
0
hi Are you call the
GetAsync
?var entity = await _entityNameRepository.GetAsync(id)
Can you share a simple project with me ?
-
0
Hi,
I have updated the code with the changes in the repo that I shared with you earlier. Please let me know.
Thank you
-
0
hi maliming,
the getasync works but it doesnt show the other 2 collections, but when using getextendedasync it shows all 3 collections except the 2 subcollections.
Which shall we use?
The queryable extension was for withdetailsasync right? Is it enough to add the relationships for those 2 collections in the queryableextension?
Thank you :)
-
0
Maliming,
Meanwhile could you please remove the screenshot of the debugging screen?
Thank you
-
0
Deleted. : )