Example #1
0
        public int Update <T>(Action <T> updater, Func <T, bool> finder) where T : class
        {
            if (updater is null)
            {
                throw new ArgumentNullException(nameof(updater));
            }

            if (finder is null)
            {
                throw new ArgumentNullException(nameof(finder));
            }

            using (var context = new GenericDbContext(_connectionString))
            {
                var data   = context.Set <T>();
                var target = data.FirstOrDefault(finder);

                if (target is null)
                {
                    return(0);
                }

                updater.Invoke(target);

                return(context.SaveChanges());
            }
        }
Example #2
0
        public T Query <T>(Func <T, bool> finder = null) where T : class
        {
            using (var context = new GenericDbContext(_connectionString))
            {
                var data = context.Set <T>();

                return(finder is null?data.FirstOrDefault() : data.FirstOrDefault(finder));
            }
        }
Example #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, GenericDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();
            DbInitializer.Initialize(context);
        }
        public void CheckIfImplicityTransactionsWorks_ShouldRollback()
        {
            InitializeSchema();

            using (var context = new GenericDbContext(ConnectionString)) {
                context.Database.ExecuteSqlCommand(TransactionalBehavior.EnsureTransaction, EmployeeInsert);
            }

            using (var context = new GenericDbContext(ConnectionString)) {
                Assert.IsFalse(context.Set<Employee>().Any());
            }
        }
        public void TestForGenericDbContext()
        {
            var optionsBuilder = new DbContextOptionsBuilder();

            //optionsBuilder.UseInternalServiceProvider
            optionsBuilder.UseSqlServer("Server=.\\sasiad;Database=AdventureWorks2014;Trusted_Connection=True;");

            using (var db = new GenericDbContext())
            {
                var deps = new GenericRepository <Department>(db).All();
            }
        }
Example #6
0
        public List <T> QueryList <T>(Func <T, bool> finder = null) where T : class
        {
            using (var context = new GenericDbContext(_connectionString))
            {
                if (finder is null)
                {
                    return(context.Set <T>().ToList());
                }

                return(context.Set <T>().Where(finder).ToList());
            }
        }
Example #7
0
        public object CreateConnection(ConnectionType type, ConnectionParams connectionParams)
        {
            object resultConnection = null;

            switch (type)
            {
                case ConnectionType.PostgreSQL:
                    NpgsqlConnection connection;
                    ConnectionPool.CreateConnection(connectionParams, out connection);
                    resultConnection = connection;

                    break;
                case ConnectionType.RavenBD:
                    resultConnection = new StoreInstance(connectionParams);

                    break;
                case ConnectionType.SQLServer:
                    GenericDbContext context = new GenericDbContext(connectionParams);
                    resultConnection = context;
                    break;
                case ConnectionType.RethinkDB:
                    try
                    {
                        //RethinkDB R = RethinkDB.R;
                        //Connection _connection = R.Connection()
                        //               .Hostname("localhost")
                        //               .Port(RethinkDBConstants.DefaultPort + 1)
                        //               .Timeout(60)
                        //               .Connect();

                        RethinkDB R = RethinkDB.R;
                        Connection _connection = R.Connection()
                                                  .Hostname(connectionParams.Server)
                                                  .Port(connectionParams.Port)
                                                  .Timeout(connectionParams.Timeout)
                                                  .Connect();

                        resultConnection = _connection;
                    }
                    catch (Exception exc)
                    {
                        //throw;
                    }

                    break;
            }

            return resultConnection;
        }
Example #8
0
        public T Delete <T>(Func <T, bool> finder) where T : class
        {
            if (finder is null)
            {
                throw new ArgumentNullException(nameof(finder));
            }

            using (var context = new GenericDbContext(_connectionString))
            {
                var data   = context.Set <T>();
                var target = data.FirstOrDefault(finder);

                return(data.Remove(target));
            }
        }
        public void CheckIfExplicityTransactionsWorks_ShouldNotRollback()
        {
            InitializeSchema();
            var executionStrategy = new SqlAzureExecutionStrategy();

            executionStrategy.Execute(() => {
                using (var context = new GenericDbContext(ConnectionString)) {
                    using (var transaction = context.Database.BeginTransaction()) {

                        context.Database.ExecuteSqlCommand(EmployeeInsert);
                        context.SaveChanges();
                        transaction.Commit();
                    }
                }
            });

            using (var context = new GenericDbContext(ConnectionString)) {
                Assert.IsTrue(context.Set<Employee>().Any());
            }
        }
Example #10
0
        public int Insert <T>(T entity, Func <T, bool> finder = null) where T : class
        {
            if (entity is null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            using (var context = new GenericDbContext(_connectionString))
            {
                var data   = context.Set <T>();
                var target = finder is null?data.FirstOrDefault() : data.FirstOrDefault(finder);

                if (finder is null || target is null)
                {
                    context.Set <T>().Add(entity);

                    return(context.SaveChanges());
                }

                return(0);
            }
        }
Example #11
0
 public Handler(GenericDbContext db, ISocketContext socketContext)
 {
     _db            = db;
     _socketContext = socketContext;
 }
 public CustomeDbContext(GenericDbContext dbContext) : base(dbContext)
 {
 }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            using (var context = new GenericDbContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    var customers = new List <Customer>
                    {
                        new Customer {
                            Id = 1, Name = "Jon Snow", Gender = "male"
                        },
                        new Customer {
                            Id = 2, Name = "Sansa Stark", Gender = "Female"
                        },
                        new Customer {
                            Id = 3, Name = "Ned Stark", Gender = "male"
                        },
                        new Customer {
                            Id = 4, Name = "Arya Stark", Gender = "male"
                        },
                        new Customer {
                            Id = 5, Name = "Sansa Stark", Gender = "Female"
                        },
                        new Customer {
                            Id = 6, Name = "Bran Stark", Gender = "male"
                        },
                        new Customer {
                            Id = 7, Name = "Benjen Stark", Gender = "male"
                        },
                        new Customer {
                            Id = 8, Name = "Tormund", Gender = "male"
                        },
                        new Customer {
                            Id = 9, Name = "Edmure Tully", Gender = "male"
                        },
                        new Customer {
                            Id = 10, Name = "Hodor", Gender = "male"
                        },
                        new Customer {
                            Id = 11, Name = "Cersei Lannister", Gender = "Female"
                        },
                        new Customer {
                            Id = 12, Name = "Tyrion Lannister", Gender = "male"
                        },
                        new Customer {
                            Id = 13, Name = "Jaime Lannister", Gender = "male"
                        },
                        new Customer {
                            Id = 14, Name = "Tywin Lannister", Gender = "male"
                        },
                        new Customer {
                            Id = 15, Name = "Daenerys Targaryen", Gender = "Female"
                        },
                        new Customer {
                            Id = 16, Name = "Rhaegar Targaryen", Gender = "male"
                        },
                        new Customer {
                            Id = 17, Name = "Joffrey Baratheon", Gender = "male"
                        },
                        new Customer {
                            Id = 18, Name = "Myrcella Baratheon", Gender = "Female"
                        },
                        new Customer {
                            Id = 19, Name = "Tommen Baratheon", Gender = "male"
                        },
                        new Customer {
                            Id = 20, Name = "Gregor Clegane", Gender = "male"
                        },
                        new Customer {
                            Id = 21, Name = "Qyburn", Gender = "male"
                        },
                        new Customer {
                            Id = 22, Name = "Catelyn Tully", Gender = "male"
                        },
                        new Customer {
                            Id = 23, Name = "Bronn", Gender = "male"
                        },
                        new Customer {
                            Id = 24, Name = "Vary", Gender = "male"
                        },
                        new Customer {
                            Id = 25, Name = "Yara Greyjoy", Gender = "Female"
                        },
                        new Customer {
                            Id = 26, Name = "Theon Greyjoy", Gender = "male"
                        },
                        new Customer {
                            Id = 27, Name = "Grey Worm", Gender = "male"
                        },
                        new Customer {
                            Id = 28, Name = "Olenna Tyrell", Gender = "Female"
                        },
                        new Customer {
                            Id = 29, Name = "Ramsay Bolton", Gender = "male"
                        },
                        new Customer {
                            Id = 30, Name = "Petyr Baelish", Gender = "male"
                        },
                        new Customer {
                            Id = 31, Name = "Lysa Tully", Gender = "Female"
                        },
                        new Customer {
                            Id = 32, Name = "Robin Arryn", Gender = "male"
                        },
                        new Customer {
                            Id = 33, Name = "Rickon Stark", Gender = "male"
                        },
                        new Customer {
                            Id = 34, Name = "Brynden Tully", Gender = "male"
                        },
                        new Customer {
                            Id = 35, Name = "Lyanna Mormont", Gender = "male"
                        },
                        new Customer {
                            Id = 36, Name = "Jorah Mormont", Gender = "male"
                        },
                        new Customer {
                            Id = 37, Name = "Jeor Mormont", Gender = "male"
                        },
                        new Customer {
                            Id = 38, Name = "Maege Mormont", Gender = "male"
                        },
                        new Customer {
                            Id = 39, Name = "Gilly", Gender = "Female"
                        },
                        new Customer {
                            Id = 40, Name = "Melisandre", Gender = "Female"
                        },
                        new Customer {
                            Id = 41, Name = "Gendry", Gender = "male"
                        },
                        new Customer {
                            Id = 42, Name = "Davos Seaworth", Gender = "male"
                        },
                        new Customer {
                            Id = 43, Name = "Robert Baratheon", Gender = "male"
                        },
                        new Customer {
                            Id = 44, Name = "Stannis Baratheon", Gender = "male"
                        },
                        new Customer {
                            Id = 45, Name = "Selyse Baratheon", Gender = "male"
                        },
                        new Customer {
                            Id = 46, Name = "Loras Tyrell", Gender = "male"
                        },
                        new Customer {
                            Id = 47, Name = "Renly Baratheon", Gender = "male"
                        },
                        new Customer {
                            Id = 48, Name = "Margaery Tyrell ", Gender = "male"
                        },
                        new Customer {
                            Id = 49, Name = "Shireen Baratheon", Gender = "male"
                        },
                        new Customer {
                            Id = 50, Name = "Samwell Tarly", Gender = "male"
                        },
                    };

                    context.Customers.AddRange(customers);
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Customers] ON");
                    context.SaveChanges();
                    context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Customers] OFF");
                    transaction.Commit();
                }
            }
        }
Example #14
0
 public Handler(GenericDbContext db)
 {
     _db = db;
 }
Example #15
0
 public FormRepository(GenericDbContext _db)
 {
     db = _db;
 }
Example #16
0
 public GenericCreateHandler(GenericDbContext context)
 {
     _context = context;
 }
Example #17
0
 public PostgreSqlDbAccessor(GenericDbContext baseDbContext)
     : base(baseDbContext)
 {
 }
Example #18
0
#pragma warning restore EF1001 // Internal EF Core API usage.

        public override IDbAccessor GetDbAccessor(GenericDbContext baseDbContext) => new PostgreSqlDbAccessor(baseDbContext);
Example #19
0
 public Handler(IReadModelRepository <Dto> dtoRepository, IReadModelRepository <RecipeDto> recipeRepository, GenericDbContext genericDbContext)
 {
     _dtoRepository    = dtoRepository ?? throw new ArgumentNullException(nameof(dtoRepository));
     _recipeRepository = recipeRepository ?? throw new ArgumentNullException(nameof(recipeRepository));
     _genericDbContext = genericDbContext;
 }
Example #20
0
 public GenericUnitOfWork(GenericDbContext dbContext)
 {
     this.Context = dbContext;
 }
Example #21
0
 public MailerDbContext(DbContextOptions <MailerDbContext> options, GenericDbContext generic) : base(options)
 {
     this.GenericDbContext = generic;
 }
 public SQLiteDbAccessor(GenericDbContext baseDbContext)
     : base(baseDbContext)
 {
 }
Example #23
0
 public UnitOfWork(GenericDbContext dbContext)
 {
     _dbContext = dbContext;
 }
 public RequestStatusRepository(GenericDbContext _db)
 {
     db = _db;
 }
Example #25
0
 public SqlServerDbAccessor(GenericDbContext baseDbContext)
     : base(baseDbContext)
 {
 }
 public MySqlDbAccessor(GenericDbContext baseDbContext)
     : base(baseDbContext)
 {
 }
Example #27
0
        private static readonly Random _rnd = new Random(); /* We just use random integers as ids */

        public GenericRepository(GenericDbContext <T> applicantsDbContext)
        {
            _applicantsDbContext = applicantsDbContext;
        }
 public AuthenticationRepository(GenericDbContext _db)
 {
     db = _db;
 }
 public MovableRepository(GenericDbContext _db)
 {
     db = _db;
 }
 public TestRepository(GenericDbContext <Guid> context, IEnumerable <IValidator <T> > validators)
 {
     _context    = context;
     _validators = validators;
 }
Example #31
0
 public OracleDbAccessor(GenericDbContext baseDbContext)
     : base(baseDbContext)
 {
 }
 public override IDbAccessor GetDbAccessor(GenericDbContext baseDbContext) => new SqlServerDbAccessor(baseDbContext);
Example #33
0
 public HomeController(GenericDbContext context)
 {
     this.context = context;
 }