public void BindDbContext <TTableInterface, TDbContextType>(DatabaseBind bind) { bind.TableInterface = typeof(TTableInterface); bind.DbContextType = typeof(TDbContextType); bind.Entities = GetAllEntityTypes(bind).ToList(); if (bind.SlaveConnections == null) { bind.SlaveConnections = new List <DbConnection>(); } if (bind.SlaveConnections.Count == 0) { bind.SlaveConnections.Add(bind.MasterConnection); } // random bind.SlaveId = new Random().Next(bind.SlaveConnections.Count); DbContextBinds.Add(bind); if (bind.CreateDbIfNotExist) { GetMaster(bind.TableInterface).Database.EnsureCreated(); } }
public IMongoCollection <T> Collection <T>(string name = "") where T : class { Type entityType = typeof(T); DatabaseBind binding = DbContextBinds.First(x => x.GetType().Equals(typeof(DatabaseBind))) as DatabaseBind; var db = GetMaster(entityType); return((db as DbContext4MongoDb).Set <T>(name)); }
/*public IMongoCollection<T> Collection<T>(string collection) where T : class * { * DatabaseBind binding = GetBinding(typeof(T)); * if (binding.DbContextMaster == null) * { * binding.DbContext = new MongoDbContext(binding.ConnectionString); * } * * return binding.DbContextSlavers.First(); * }*/ public Object Find(Type type, params string[] keys) { DatabaseBind binding = DbContextBinds.First(x => x.Entities.Contains(type)); if (binding.DbContextMaster == null || binding.DbContextMaster.Database.CurrentTransaction == null) { return(GetReader(type).Find(type, keys)); } else { return(GetMaster(type).Find(type, keys)); } }
public void BindDbContext <TTableInterface, TDbContextType>(DatabaseBind bind) { bind.TableInterface = typeof(TTableInterface); bind.DbContextType = typeof(TDbContextType); bind.Entities = GetAllEntityTypes(bind).ToList(); DbContextBinds.Add(bind); if (bind.CreateDbIfNotExist) { GetMaster(bind.TableInterface).Database.EnsureCreated(); } }
public DbSet <T> Table <T>() where T : class { Type entityType = typeof(T); DatabaseBind binding = DbContextBinds.First(x => x.Entities.Contains(entityType)); if (binding.DbContextMaster == null || binding.DbContextMaster.Database.CurrentTransaction == null) { return(GetReader(entityType).Set <T>()); } else { return(GetMaster(entityType).Set <T>()); } }
public void BindDbContext(DatabaseBind bind) { bind.Entities = GetAllEntityTypes(bind).ToList(); DbContextBinds.Add(bind); }
private List <Type> GetAllEntityTypes(DatabaseBind bind) { var assemblies = (string[])AppDomain.CurrentDomain.GetData("Assemblies"); return(Utility.GetClassesWithInterface(bind.TableInterface, assemblies)); }
public int SaveChanges() { DatabaseBind binding = DbContextBinds.Where(x => x.DbContextType != null).First(x => x.DbContextMaster != null && x.DbContextMaster.Database.CurrentTransaction != null); return(binding.DbContextMaster.SaveChanges()); }