Ejemplo n.º 1
0
        public virtual IDbContextRepository <T> GetGenericRepository <T>() where T : class
        {
            if (this._genericRepositories.ContainsKey(typeof(T)))
            {
                return(this._genericRepositories[typeof(T)] as IDbContextRepository <T>);
            }

            DbContextRepository <C, T> repository = new DbContextRepository <C, T>(this.Context);

            this._genericRepositories[typeof(T)] = repository;

            return(repository);
        }
Ejemplo n.º 2
0
        private async Task DealWithBatchAsync()
        {
            using (var scope = _serviceProvider.CreateScope())
                using (var _context = (ProjectDbContext)scope.ServiceProvider.GetRequiredService(typeof(ProjectDbContext)))
                    using (IRepository <TestModel> _repository = new DbContextRepository <TestModel>(_context))
                    {
                        for (var i = 0; i < 1000; i++)
                        {
                            _repository.Add(_fixture.Build <TestModel>()
                                            .With(x => x.Id, 0)
                                            .With(x => x.Nested1TestModel, (_fixture.Build <Nested1TestModel>().With(x => x.Id, 0).Create()))
                                            .Create()
                                            );
                        }

                        await _repository.SaveAsync(); // final save for items outside of the batch
                    }

            Console.WriteLine("Worked on 1k");
        }
Ejemplo n.º 3
0
        public override void OnException(
            System.Web.Http.Filters.HttpActionExecutedContext actionExecutedContext)
        {
            if (actionExecutedContext.Exception != null)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(actionExecutedContext.Exception);
                try
                {
                    using (var dbcontext = new DbContextRepository())
                    {
                        ErrorLog errorLog = new ErrorLog();

                        errorLog.MethodName     = actionExecutedContext.Exception.TargetSite.Name;
                        errorLog.ControllerName = actionExecutedContext.Exception.TargetSite.DeclaringType.Name;
                        var customAtttribute = actionExecutedContext.Exception.TargetSite.CustomAttributes;
                        foreach (var attr in customAtttribute)
                        {
                            errorLog.VerbAttribute = attr.AttributeType.Name;
                            break;
                        }

                        errorLog.ErrorMessage = actionExecutedContext.Exception.Message;

                        errorLog.UserId                 = 1;
                        errorLog.CreatedDate            = DateTime.UtcNow;
                        dbcontext.Entry(errorLog).State = EntityState.Added;
                        dbcontext.ErrorLogs.Add(errorLog);
                        dbcontext.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                }
            }


            base.OnException(actionExecutedContext);
        }