public static void DisconnectDb(ref PostgreSQLContext context) { // if (context != null) // { // context.Dispose(); // } context?.Dispose(); context = null; }
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(); } }
//没有共通化 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"); } } } }
public MoviesController(PostgreSQLContext context) { _context = context; }
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); }
/// <summary> /// 配置方法翻译解析器。 /// </summary> static void ConfigureMethodHandler() { PostgreSQLContext.SetMethodHandler("StringLike", new PostgreSQL_StringLike_MethodHandler()); }
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)); }
public PersonRepository(PostgreSQLContext context) { _context = context; }
public UserRepository(PostgreSQLContext context) { _context = context; }
public Repository(PostgreSQLContext context) { _context = context; _dataset = context.Set <TEntidade>(); }
public BuscaController(PostgreSQLContext context) { _context = context; }
public UsersController(PostgreSQLContext context) { _context = context; }
public TodoItemRepository(PostgreSQLContext postgreSQLContext) { _dbContext = postgreSQLContext ?? throw new ArgumentNullException($"{nameof(postgreSQLContext)}"); }
private static IDbContext CreatePostgreSQLContext(string connString) { var dbContext = new PostgreSQLContext(new NpgsqlConnectionFactory(connString)); return(dbContext); }
public static void ConnectDb(out PostgreSQLContext context) { // if (context != null) return; // context = PostgreSQLContext.Instance; context = new PostgreSQLContext(new DbContextOptions <PostgreSQLContext>()); }
static IDbContext CreatePostgreSQLContext(string connString) { PostgreSQLContext dbContext = new PostgreSQLContext(new PostgreSQLConnectionFactory(connString)); return(dbContext); }
public PersonRepository(PostgreSQLContext context) : base(context) { }
public SearchController(PostgreSQLContext context) { _context = context; }
public Repository(PostgreSQLContext context) { _context = context; dataset = context.Set <T>(); }
public CursoRepository(PostgreSQLContext context) : base(context) { }