private static void Compare(Dictionary <string, Dictionary <string, EntityBase> > dbDic, Dictionary <string, Dictionary <string, EntityBase> > newDic) { Dictionary <string, ConnectionInfo> connDic = ConnectionProviderBase.GetAllConnectionInfos(); foreach (var conn in newDic.Keys) { IDBOperatorBase manager = InjectContainer.Resolve <IDBOperatorBase>(connDic[conn].DBType.ToString()); foreach (var entityName in newDic[conn].Keys) { if (!dbDic[conn].ContainsKey(entityName)) { //新增表 manager.CreateTable(newDic[conn][entityName], conn); newDic[conn][entityName].Id = Guid.NewGuid().ToString(); manager.InsertIntoEntityBase(newDic[conn][entityName], conn); foreach (var attr in newDic[conn][entityName].Attributes.Keys) { newDic[conn][entityName].Attributes[attr].Id = Guid.NewGuid().ToString(); newDic[conn][entityName].Attributes[attr].EntityId = newDic[conn][entityName].Id; manager.InsertIntoEntityAttributeBase(newDic[conn][entityName].Attributes[attr], conn); } } else { newDic[conn][entityName].Id = dbDic[conn][entityName].Id; foreach (var attrName in newDic[conn][entityName].Attributes.Keys) { newDic[conn][entityName].Attributes[attrName].EntityId = newDic[conn][entityName].Id; if (!dbDic[conn][entityName].Attributes.ContainsKey(attrName)) { //新增字段 manager.CreateField(entityName, newDic[conn][entityName].Attributes[attrName], conn); newDic[conn][entityName].Attributes[attrName].Id = Guid.NewGuid().ToString(); manager.InsertIntoEntityAttributeBase(newDic[conn][entityName].Attributes[attrName], conn); } else { newDic[conn][entityName].Attributes[attrName].Id = dbDic[conn][entityName].Attributes[attrName].Id; } } } } } _datasourceInfo = newDic; }
/// <summary> /// 初始化,其中包括同步Table.xml信息到数据库,并且加载新的Entity信息到内存中 /// </summary> public static void Init() { var dbSource = new Dictionary <string, Dictionary <string, EntityBase> >(); InjectContainer.LoadConnection(); Dictionary <string, ConnectionInfo> connDic = ConnectionProviderBase.GetAllConnectionInfos(); if (connDic.Count > 0) { List <string> removeConns = new List <string>(); foreach (var key in connDic.Keys) { if (_datasourceInfo.ContainsKey(key)) { var dbType = connDic[key].DBType; IDBOperatorBase manager = InjectContainer.Resolve <IDBOperatorBase>(dbType.ToString()); if (!manager.DatabaseExist(key)) { manager.CreateDatabase(key); } if (!manager.TableExist("EntityBase", key)) { manager.CreateDefaultTable(key); } var entityDic = manager.QueryEntityDic(key); dbSource.Add(key, entityDic); } else { removeConns.Add(key); } } ConnectionProviderBase.DeleteConnections(removeConns); } Compare(dbSource, _datasourceInfo); }
public int Update <T>(T data) { IDBOperatorBase service = InjectContainer.ResolveByName <IDBOperatorBase>(_condition.ConnectionName); return(service.Update(_condition, data)); }
public int Delete() { IDBOperatorBase service = InjectContainer.ResolveByName <IDBOperatorBase>(_condition.ConnectionName); return(service.Delete(_condition)); }
public T SingleQuery <T>() { IDBOperatorBase service = InjectContainer.ResolveByName <IDBOperatorBase>(_condition.ConnectionName); return(service.Query <T>(_condition).FirstOrDefault()); }
public List <T> Query <T>() { IDBOperatorBase service = InjectContainer.ResolveByName <IDBOperatorBase>(_condition.ConnectionName); return(service.Query <T>(_condition)); }
public int Insert <T>(List <T> datas) { IDBOperatorBase service = InjectContainer.ResolveByName <IDBOperatorBase>(_condition.ConnectionName); return(service.Insert <T>(_condition, datas)); }