/// <inheritdoc/> public IRepository SelectRepository(Type entityType, bool memRepositoryEnabled = true) { var mainRepository = _mainRepositoryMapping[entityType]; // 是否启用了 MemoryRepository? if (memRepositoryEnabled) { var isStaticEntity = PersistenceConfig.IsStaticConfigTable(entityType); var isDynamicEntity = PersistenceConfig.IsDynamicConfigTable(entityType); // 如果为“静态配置表” || “为动态配置表且此表所在的远程库没有连接” if (isStaticEntity || (isDynamicEntity && !mainRepository.Connected)) { return(this.MemoryRepository); } else { return(_mainRepositoryMapping[entityType]); } } else { // 主用库是否连接? if (mainRepository.Connected) { return(mainRepository); } else { _backupRepositoryMapping.TryGetValue(entityType, out Repository backupRepository); return(backupRepository); } } }
/// <summary> /// /// </summary> public void Update <T>(object instance, Expression <Func <T, bool> > predicate) where T : Entity { // 如果是静态数据,则不允许此操作。 var entityType = typeof(T); if (PersistenceConfig.IsStaticConfigTable(entityType)) { throw new InvalidOperationException(string.Format($"{entityType.Name} 为静态配置数据,无法执行Update操作。")); } var theRepository = _repositorySelector.SelectRepository(typeof(T)); if (theRepository == null) { throw new InvalidOperationException(); } else { theRepository.Update(instance, predicate); } }
/// <summary> /// /// </summary> public void AsyncInsert <T>(T[] entities, Action <Exception> exceptionHandler) where T : Entity { // 如果是静态数据,则不允许此操作。 var entityType = typeof(T); if (PersistenceConfig.IsStaticConfigTable(entityType)) { throw new InvalidOperationException(string.Format($"{entityType.Name} 为静态配置数据,无法执行AsyncInsert操作。")); } var theRepository = _repositorySelector.SelectRepository(typeof(T)); if (theRepository == null) { throw new InvalidOperationException(); } else { theRepository.AsyncInsert(entities, exceptionHandler); } }