Base solution for your next web application

Activities of "SASIMEXICO"

Hi,

Add/Create m-n link ok.

        var organizationUnitListCall = await GetOrganizationUnits();
        var organizationUnitList = organizationUnitListCall.Items.ToList();
        for (int i = 0; i < input.OUs.Count; i++)
        {
            var organizationUnitDto = organizationUnitList.Where(x => x.Id == input.OUs[i]).FirstOrDefault();
            var organizationUnit = _objectMapper.Map<OrganizationUnitGT>(organizationUnitDto);
            organizationUnit.TenantId = teleWorkingAudit.TenantId;
            if (organizationUnit != null)
                teleWorkingAudit.TeleWorkingAuditOrganizationUnitGTs.Add(new TeleWorkingAuditOrganizationUnitGT() { OrganizationUnitGT = organizationUnit, OrganizationUnitGTId = organizationUnit.Id });
        }

----> the error is here, when everything is saved

    await _teleWorkingAuditRepository.InsertOrUpdateAsync(teleWorkingAudit);
    
    

Hi, I have extended a non-abstract entity "OrganizationUnits" and created "OrganizationUnitGT". It works fine adding new parameters such as "ExternalCode". Now I want to add a new relation, it is an M-N relation with my Entity "TeleWorkingAudit". But I have the following problem:

"*The instance of entity type 'OrganizationUnitGT' 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.
System.InvalidOperationException: The instance of entity type 'OrganizationUnitGT' 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.
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.ThrowIdentityConflict(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(TKey key, InternalEntityEntry entry, Boolean updateDuplicate)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(TKey key, InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTracking(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode`1 node)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.AttachGraph(InternalEntityEntry rootEntry, EntityState targetState, EntityState storeGeneratedWithKeySetTargetState, Boolean forceStateWhenUnknownKey)
   at Microsoft.EntityFrameworkCore.DbContext.SetEntityState(InternalEntityEntry entry, EntityState entityState)
   at Microsoft.EntityFrameworkCore.DbContext.SetEntityState[TEntity](TEntity entity, EntityState entityState)
   at Microsoft.EntityFrameworkCore.DbContext.Add[TEntity](TEntity entity)
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.Add(TEntity entity)
   at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.Insert(TEntity entity)
   at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.InsertAsync(TEntity entity)
   at Abp.Domain.Repositories.AbpRepositoryBase`2.InsertOrUpdateAsync(TEntity entity)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at GenTime.AppService.TeleWorkingAuditAppService.CreateAsync(CreateTeleWorkingAuditDto input) in C:\Users\mmartinez5\Documents\gitsasi\gentime.backend\src\GenTime.Application\GenTime\AppService\TeleWorkingAuditAppService.cs:line 399
   at Abp.Authorization.AuthorizationInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at Abp.Auditing.AuditingInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at Abp.Runtime.Validation.Interception.ValidationInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at lambdamethod(Closure , Object )
   at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
   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|250(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.ThrowIdentityConflict(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(TKey key, InternalEntityEntry entry, Boolean updateDuplicate)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(TKey key, InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTracking(InternalEntityEntry entry)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode`1 node)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.AttachGraph(InternalEntityEntry rootEntry, EntityState targetState, EntityState storeGeneratedWithKeySetTargetState, Boolean forceStateWhenUnknownKey)
   at Microsoft.EntityFrameworkCore.DbContext.SetEntityState(InternalEntityEntry entry, EntityState entityState)
   at Microsoft.EntityFrameworkCore.DbContext.SetEntityState[TEntity](TEntity entity, EntityState entityState)
   at Microsoft.EntityFrameworkCore.DbContext.Add[TEntity](TEntity entity)
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.Add(TEntity entity)
   at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.Insert(TEntity entity)
   at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase`3.InsertAsync(TEntity entity)
   at Abp.Domain.Repositories.AbpRepositoryBase`2.InsertOrUpdateAsync(TEntity entity)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at GenTime.AppService.TeleWorkingAuditAppService.CreateAsync(CreateTeleWorkingAuditDto input) in C:\Users\mmartinez5\Documents\gitsasi\gentime.backend\src\GenTime.Application\GenTime\AppService\TeleWorkingAuditAppService.cs:line 399
   at Abp.Authorization.AuthorizationInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at Abp.Auditing.AuditingInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at Abp.Runtime.Validation.Interception.ValidationInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at lambda_method(Closure , Object )
   at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeActionMethodAsync&gt;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)*".

Here I attach my code.

Entity - OrganizationUnitGT (extended from "OrganizationUnit")

namespace GenTime.Model
{
    /// <summary>
    /// Represents an extended organization unit in the system.
    /// </summary>
    public class OrganizationUnitGT : OrganizationUnit
    {
        public virtual string ExternalCode { get; set; }
        public ICollection<TeleWorkingAuditOrganizationUnitGT> TeleWorkingAuditOrganizationUnitGTs { get; set; }

        public OrganizationUnitGT()
        {
            TeleWorkingAuditOrganizationUnitGTs = new HashSet<TeleWorkingAuditOrganizationUnitGT>();
        }

    }
}

Entity - TeleWorkingAudit

namespace GenTime.Model
{
    public partial class TeleWorkingAudit : FullAuditedEntity, IMayHaveTenant
    {
        public TeleWorkingAudit()
        {
            TeleWorkingAuditApplications = new HashSet<TeleWorkingAuditApplication>();
            TeleWorkingAuditTeleWorkingControlGroups = new HashSet<TeleWorkingAuditTeleWorkingControlGroup>();
            TeleWorkingAuditUsers = new HashSet<TeleWorkingAuditUser>();
            TeleWorkingAuditOrganizationUnitGTs = new HashSet<TeleWorkingAuditOrganizationUnitGT>();
        }

        public int DesiredUse { get; set; }
        public int? RealUse { get; set; }
        public string DesiredTimeUse { get; set; }
        public long RealTimeUse { get; set; }
        public string UseTopDown { get; set; }

        public string FromHour { get; set; }
        public string ToHour { get; set; }
        public int[] DaySelected { get; set; }

        public int? TenantId { get; set; }

        public ICollection<TeleWorkingAuditApplication> TeleWorkingAuditApplications { get; set; }
        public ICollection<TeleWorkingAuditTeleWorkingControlGroup> TeleWorkingAuditTeleWorkingControlGroups { get; set; }
        public ICollection<TeleWorkingAuditUser> TeleWorkingAuditUsers { get; set; }
        public ICollection<TeleWorkingAuditOrganizationUnitGT> TeleWorkingAuditOrganizationUnitGTs { get; set; }
    }
}

MN Class - TeleWorkingAuditOrganizationUnitGT

namespace GenTime.Model
{
    public partial class TeleWorkingAuditOrganizationUnitGT
    {
        public int TeleWorkingAuditId { get; set; }
        public TeleWorkingAudit TeleWorkingAudit { get; set; }

        public long OrganizationUnitGTId { get; set; }
        public OrganizationUnitGT OrganizationUnitGT { get; set; }
    }
}

What am I doing wrong? What should modify or add?

Thanks in advance for your help.

Thanks for the reply.

Regards

Hi,

I need to connect as Host to get the Tenant that are defined. But when I pass the "Abp.TenantId" as null in the Header of the HttpClient, the TokenResponse gives me the error of invalid_grant. If "Abp.TenantId" is not null, I don't have problem. In BackEnd (server), the version of Abp is 5.5.0.

In this EndPoint, I'm using a IdentityModel 4.2.0

private async Task&lt;TokenResponse&gt; RequestToken()
        {
            int retryCount = 0;
            TokenResponse res = null;

            bool isTokenEmpty = true;
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var disco = await client.GetDiscoveryDocumentAsync(_tokenEndpoint.TrimEnd('/'));
                    if (disco.IsError)
                    {
                        throw new Exception(disco.Error);
                    }
                    client.DefaultRequestHeaders.Add("Abp.TenantId", string.IsNullOrEmpty(_tenantId.ToString()) ? null : _tenantId.ToString());  //Set TenantId
                    do
                    {
                        retryCount++;
                        try
                        {
                            // request token
                            var tokenResponse = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
                            {
                                Address = disco.TokenEndpoint,
                                ClientId = "client",
                                ClientSecret = _secretToken,

                                UserName = _userToken,
                                Password = _passToken,
                                //TODO: passar-ho al config
                                Scope = "default-api"
                            });

                            if (tokenResponse.IsError)
                            {
                                _log.Error(tokenResponse.Error);
                            }
                            else
                                isTokenEmpty = false;

                            _log.Debug(tokenResponse.Json);
                            res = tokenResponse;
                        }
                        catch (Exception ex)
                        {
                            Exception inner = ex;
                            while (inner.InnerException != null)
                            {
                                inner = inner.InnerException;
                            };

                            _log.DebugFormat("Error requesting credentials: {1}, Retrying={0}", retryCount, inner.Message);
                            Thread.Sleep(5000);
                        }
                    } while (isTokenEmpty && retryCount <= 2);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
            return res;
        }

Thanks for all Regards.

hi, yes @ismcagdas https://support.aspnetzero.com/QA/Questions/8312#answer-94253803-8dc2-e802-c07f-39f2b7334ae0

I will try with net core 3.1, thanks @Mahinthan

hi @maliming,

the problem occurs with iis and iisexpress only. You can test it with iexplorer 11.

Hi,

@ismcagdas, @Mahinthan, @smry the problem is with the OPTIONS request and the 204 response. Some browsers hangs or timeout after 30' (iexplorer). The solution is to manage the response headers.

if (context.Request.Method == "OPTIONS") { context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { (string)context.Request.Headers["Origin"] }); context.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "Origin,X-Requested-With,Content-Type,Accept,.aspnetcore.culture,abp.tenantid,pragma,cache-control,expires,authorization" });         context.Response.Headers.Add("Access-Control-Allow-Methods", new[] { "GET, POST, PUT, DELETE, OPTIONS" });         context.Response.Headers.Add("Access-Control-Allow-Credentials", new[] { "true" }); context.Response.StatusCode = 200; return context.Response.WriteAsync("OK"); } return _next.Invoke(context);

After that we can load the webapp on mobile and iexplorer 11.

cheers

I have a IIS Server 10 with SSL certificate (https) and Zero not load AbpUserConfiguration/GetAll in Safari (Mac) and iOS (any browser), then the Login page never appears. There aren't any error in Logs. Spinner loader appears and spinning for ever.

In IE 11 (Windows 10) after 2 minutes waiting, the page is loaded. Afterwards the application continues to run very slow.

Any solution? Thanks.

Hi,

.net core + Angular version 4.9

This table contain one-to-many relation with herself. Each record contain a ParentId and List of Childs

I don't need Include and ThenInclude, I need in the same table, one register contain a child, this child have a parent and other child in the same time, this child contain a parent and child...

when make -> var query = ruleRepository.GetAllIncluding(x => x.Childs, x => x.ListRuleValidators); Only one level of depth returns

I hope that parent returns with his children and his children with his children... but those children (have other children) do not show them.

Regards

Hi,

I have a table with a 1..N relationship with herself. When I do a GetAllIncluding, it only gives me a one level of depth (ruleRepository.GetAllIncluding(x => x.Childs)), when the Childs has another Childs (4 levels of deep, relations). How can I do to give me all levels of depth?

Best Regards and thank you very much Toni

Showing 41 to 50 of 81 entries