Esempio n. 1
0
 public static void DisconnectDb(ref PostgreSQLContext context)
 {
     // if (context != null)
     // {
     //     context.Dispose();
     // }
     context?.Dispose();
     context = null;
 }
Esempio n. 2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new PostgreSQLContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <PostgreSQLContext> >()))
            {
                // Look for any movies.
                if (context.Movies.Any())
                {
                    return;   // DB has been seeded
                }

                context.Movies.AddRange(
                    new Movie
                {
                    Title       = "When Harry Met Sally",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = "Romantic Comedy",
                    Price       = 7.99M,
                    Rating      = "普"
                },

                    new Movie
                {
                    Title       = "Ghostbusters ",
                    ReleaseDate = DateTime.Parse("1984-3-13"),
                    Genre       = "Comedy",
                    Price       = 8.99M,
                    Rating      = "普"
                },

                    new Movie
                {
                    Title       = "Ghostbusters 2",
                    ReleaseDate = DateTime.Parse("1986-2-23"),
                    Genre       = "Comedy",
                    Price       = 9.99M,
                    Rating      = "普"
                },

                    new Movie
                {
                    Title       = "Rio Bravo",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = "Western",
                    Price       = 3.99M,
                    Rating      = "普"
                }
                    );
                context.SaveChanges();
            }
        }
Esempio n. 3
0
        //没有共通化
        public int SaveSalonService(string salonCd, ObservableCollection <ServiceModel> models)
        {
            using (var context = new PostgreSQLContext())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        int res           = 0;
                        var salonServices = context.SalonServices.Where(s => s.SalonCode == salonCd).Include(s => s.Service).ToList();
                        var data          = salonServices.Where(w => !models.Select(s => s.Code).Contains(w.Service.Code));
                        context.SalonServices.RemoveRange(data);


                        foreach (ServiceModel model in models)
                        {
                            if (salonServices.Where(w => w.Service.Code == model.Code).Count() < 1)
                            {
                                DBModels.PostgreSQL.SalonService salon   = new DBModels.PostgreSQL.SalonService();
                                DBModels.PostgreSQL.Service      service = context.Services.Where(s => s.Code == model.Code).First();

                                salon.SalonCode   = salonCd;
                                salon.ServiceCode = model.Code;
                                salon.Service     = service;
                                context.SalonServices.Add(salon);
                            }
                        }

                        res += context.SaveChanges();

                        transaction.Commit();
                        return(res);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        AppLog.Error(typeof(SalonControl), ex.ToString());
                        throw new AppException("DBException");
                    }
                }
            }
        }
Esempio n. 4
0
 public MoviesController(PostgreSQLContext context)
 {
     _context = context;
 }
Esempio n. 5
0
        protected override IDbContext CreateDbContext()
        {
            IDbContext dbContext = new PostgreSQLContext(new PostgreSQLConnectionFactory("User ID=postgres;Password=sasa;Host=localhost;Port=5432;Database=Chloe;Pooling=true;"));

            return(dbContext);
        }
Esempio n. 6
0
 /// <summary>
 /// 配置方法翻译解析器。
 /// </summary>
 static void ConfigureMethodHandler()
 {
     PostgreSQLContext.SetMethodHandler("StringLike", new PostgreSQL_StringLike_MethodHandler());
 }
Esempio n. 7
0
        public PostgreSQLDemo()
        {
            this._dbContext = new PostgreSQLContext(new PostgreSQLConnectionFactory("User ID=postgres;Password=sasa;Host=localhost;Port=5432;Database=Chloe;Pooling=true;"));

            DbConfiguration.UseTypeBuilders(typeof(TestEntityMap));
        }
Esempio n. 8
0
 public PersonRepository(PostgreSQLContext context)
 {
     _context = context;
 }
Esempio n. 9
0
 public UserRepository(PostgreSQLContext context)
 {
     _context = context;
 }
 public Repository(PostgreSQLContext context)
 {
     _context = context;
     _dataset = context.Set <TEntidade>();
 }
 public BuscaController(PostgreSQLContext context)
 {
     _context = context;
 }
Esempio n. 12
0
 public UsersController(PostgreSQLContext context)
 {
     _context = context;
 }
Esempio n. 13
0
 public TodoItemRepository(PostgreSQLContext postgreSQLContext)
 {
     _dbContext = postgreSQLContext ?? throw new ArgumentNullException($"{nameof(postgreSQLContext)}");
 }
Esempio n. 14
0
        private static IDbContext CreatePostgreSQLContext(string connString)
        {
            var dbContext = new PostgreSQLContext(new NpgsqlConnectionFactory(connString));

            return(dbContext);
        }
Esempio n. 15
0
 public static void ConnectDb(out PostgreSQLContext context)
 {
     // if (context != null) return;
     // context = PostgreSQLContext.Instance;
     context = new PostgreSQLContext(new DbContextOptions <PostgreSQLContext>());
 }
Esempio n. 16
0
        static IDbContext CreatePostgreSQLContext(string connString)
        {
            PostgreSQLContext dbContext = new PostgreSQLContext(new PostgreSQLConnectionFactory(connString));

            return(dbContext);
        }
Esempio n. 17
0
 public PersonRepository(PostgreSQLContext context) : base(context)
 {
 }
 public SearchController(PostgreSQLContext context)
 {
     _context = context;
 }
Esempio n. 19
0
 public Repository(PostgreSQLContext context)
 {
     _context = context;
     dataset  = context.Set <T>();
 }
Esempio n. 20
0
 public CursoRepository(PostgreSQLContext context) : base(context)
 {
 }