public async Task <T> Create(T entity, string alias = "", bool sendObjFirebase = true, List <string> includeExpressions = null) { // var objstr = JsonSerializer.Serialize(entity); //_logger.LogInformation($"----------------------------objstr {objstr}"); var cacheKeySize = string.Format("_{0}_size", model); _cache.Remove(cacheKeySize); nameModel = $"create_{nameModel}"; try { entity.GetType().GetProperty("created_by_id")?.SetValue(entity, GetCurrentUser(), null); var obj = _context.Add(entity); _context.SaveChanges(); if (_optionsDelegate.CurrentValue.EnableAudit) { await _cRepositoryLog.AddLog(_context, new AuditBinding() { action = AudiState.CREATE, objeto = typeof(T).Name, }, id : GetKey(entity), commit : true); } includeExpressions?.ForEach(x => _context.Entry(obj.Entity).Reference(x).Load()); if (sendObjFirebase) { SendStatus(GraphGrpcStatus.CREATE, GetKey(entity)); } if (!string.IsNullOrEmpty(GetCurrentUser())) { _handleMsg.GetStream().OnNext(entity); } return(obj.Entity); } catch (ValidationException exc) { _logger.LogError(exc, $"{nameof(Create)} validation exception: {exc?.Message}"); _fillDataExtensions.Add($"{(string.IsNullOrEmpty(alias) ? nameModel : alias)}", $"{exc?.Message }"); _context.Entry(entity).State = EntityState.Detached; } catch (DbUpdateException e) { _logger.LogError(e, $"{nameof(Create)} db update error: {e?.InnerException?.Message}"); _fillDataExtensions.Add($"{(string.IsNullOrEmpty(alias) ? nameModel : alias)}", $"{ e.InnerException?.Message }"); _context.Entry(entity).State = EntityState.Detached; } return(entity); }