Starts in:
1 DAY
12 HRS
39 MIN
49 SEC
Starts in:
1 D
12 H
39 M
49 S

Activities of "Neozzz"

We have the following relationships:

public class Employee : FullAuditedEntity<Guid>
{
    <<<<properties....>>>
    public ICollection<Contact> Contacts {get;set;}   
}

public class Contact : FullAuditedEntity<Guid>
{
    <<<properties...>>>
    public ICollection<Address> Addresses {get;set;}
}

An employee can have multiple contacts and each contact can have multiple addresses. The following is a snippet of the json request for POST

{
"FirstName":"Neo",
"LastName":"Xav",
"Age":"20",
"Contact":[
{...},
{...},
{"Address":[{...},{...}]}
]
}

However I am getting the below error from logs when I use the CreateAsync method: The instance of entity type 'Contact' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.

Please let me know what might be causing the issue.

Thank you

  • ABP Framework version: v4.4.2
  • UI type: swagger
  • DB provider: EF Core

Maliming,

Meanwhile could you please remove the screenshot of the debugging screen?

Thank you

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 :)

Hi,

I have updated the code with the changes in the repo that I shared with you earlier. Please let me know.

Thank you

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 :)

Hi maliming,

Should I use WithDetailsAsync as well along with it or this is separate?

TY

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();

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.

Hi maliming,

I've sent you a request to the repo on github.

Thank you

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.&lt;InvokeNextActionFilterAsync&gt;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.&lt;InvokeInnerFilterAsync&gt;g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeNextExceptionFilterAsync&gt;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
Showing 71 to 80 of 128 entries
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06