private static DMSDbProvider GetProvider(DMSDbType dbType) { Type type = typeof(DMS.MssqlObject); if (dbType != DMSDbType.MsSql) { switch (dbType) { case DMSDbType.Access: type = typeof(DMS.AccessObject); break; case DMSDbType.Mysql: type = typeof(DMS.MysqlObject); break; case DMSDbType.Oracle: type = typeof(DMS.OracleObject); break; case DMSDbType.SQLite: type = typeof(DMS.SQLiteObject); break; default: break; } } TableMappingAttribute attribute = DMSExpression.GetTableMappingAttribute(type); var provider = DMSExpression.GetDbProvider(attribute.DMSDbType, attribute.ConfigName); return(provider); }
/// <summary> /// 执行查询的存储过程,不分页 /// </summary> /// <typeparam name="T">类型参数必须是引用类型;这一点也适用于任何类、接口、委托或数组类型。</typeparam> /// <param name="iEntity">参数实体</param> /// <param name="errMsg">错误信息</param> /// <returns></returns> private IEnumerable <T> GetListing <T>(ISPEntity iEntity, ref string errMsg) where T : class { StoredProcedureMappingAttribute attribute = DMSExpression.GetStoredProcedureMappingAttribute(iEntity.GetType()); DMSDbProvider provider = DMSExpression.GetDbProvider(attribute.DMSDbType, attribute.ConfigName); using (var conn = provider.GetOpenConnection()) { DynamicParameters parameters = GetParameters(iEntity); return(DMSDbAccess.Query <T>(conn, attribute.Name, attribute.Name, parameters, 0, null, true, 30, System.Data.CommandType.StoredProcedure)); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TResult"></typeparam> /// <param name="dms"></param> /// <param name="strSql"></param> /// <param name="dbParams"></param> /// <returns></returns> public static IEnumerable <TResult> Query <T, TResult>(this DMS <T> dms, string strSql, dynamic dbParams) where T : class where TResult : class { TableMappingAttribute attribute = DMSExpression.GetTableMappingAttribute(typeof(T)); var provider = DMSExpression.GetDbProvider(attribute.DMSDbType, attribute.ConfigName); using (var conn = provider.GetOpenConnection()) { return(DMSFrame.Access.DMSDbAccess.Query <TResult>(conn, typeof(TResult).FullName, strSql, dbParams, 0, null, true, 30)); } }
/// <summary> /// /// </summary> /// <param name="elementType"></param> private void changeInternalDbProvider(Type elementType) { if (elementType == null) { return; } if (InternalDbProvider != null) { return; } TableMappingAttribute attribute = DMSExpression.GetTableMappingAttribute(elementType); string configName = attribute == null ? ConstExpression.TableConfigConfigName : attribute.ConfigName; this.InternalDbProvider = DMSExpression.GetDbProvider(attribute == null ? DMSDbType.MsSql : attribute.DMSDbType, configName); }
/// <summary> /// /// </summary> /// <param name="elementType"></param> private void changeInternalDbProvider(Type elementType) { if (elementType == null) { return; } if (InternalDbProvider != null) { return; } DMSDbType dbType = elementType.GetDMSDbType(); string configName = elementType.GetEntityTableMappingConfigName(); this.InternalDbProvider = DMSExpression.GetDbProvider(dbType, configName); InternalDMSDbType = dbType; }
/// <summary> /// 执行更新,删除,插入的存储过程 /// </summary> /// <param name="iEntity">存储过程实体类</param> /// <param name="errMsg">错误信息</param> /// <returns></returns> public bool ExecuteNoQuery(ISPEntity iEntity, ref string errMsg) { StoredProcedureMappingAttribute attribute = DMSExpression.GetStoredProcedureMappingAttribute(iEntity.GetType()); DMSDbProvider provider = DMSExpression.GetDbProvider(attribute.DMSDbType, attribute.ConfigName); using (var conn = provider.GetOpenConnection()) { DynamicParameters parameters = GetParameters(iEntity); int resultValue = DMSDbAccess.Execute(conn, attribute.Name, attribute.Name, parameters, null, 30, System.Data.CommandType.StoredProcedure); if (resultValue > 0) { return(true); } return(false); } }
/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="bDataBase"></param> /// <param name="bWithLock"></param> /// <param name="bNeedParams"></param> /// <param name="bNeedQueryProvider"></param> protected DMS(Type type, string bDataBase, bool bWithLock, bool bNeedParams, bool bNeedQueryProvider) { DMSFrameException.ThrowIfNull(type); this.DataType = type; this.CurrentType = type; TableMappingAttribute attribute = DMSExpression.GetTableMappingAttribute(type); this.TableExpressioin = DMSExpression.GetTableExpression(attribute.DMSDbType); this.ColumnsExpressioin = DMSExpression.GetColumnsExpression(attribute.DMSDbType); this.WhereExpressioin = DMSExpression.GetWhereExpression(attribute.DMSDbType); this.OrderByExpressioin = DMSExpression.GetOrderByExpression(attribute.DMSDbType); this.GroupByExpression = DMSExpression.GetGroupByExpression(attribute.DMSDbType); this.HavingExpression = DMSExpression.GetHavingExpression(attribute.DMSDbType); this.SplitExpression = DMSExpression.GetSplitExpression(attribute); this.Provider = DMSExpression.GetDbProvider(attribute.DMSDbType, attribute.ConfigName); this.dynamicParameters = new DynamicParameters(); DMSFrameException.ThrowIfNull(this.TableExpressioin, this.ColumnsExpressioin, this.WhereExpressioin, this.OrderByExpressioin, this.GroupByExpression, this.HavingExpression); if (!string.IsNullOrEmpty(bDataBase)) { this.TableExpressioin.bDataBase = bDataBase; DMSDataBase myDb = new DMSDataBase(bDataBase); this.TableExpressioin.Append <DMSDataBase, DMSDataBase>(q => myDb); } this.TableExpressioin.WithLock = bWithLock; this.ExcuteType = DMSExcuteType.SELECT; this.TableExpressioin.NeedParams = bNeedParams; this.ColumnsExpressioin.NeedParams = bNeedParams; this.WhereExpressioin.NeedParams = bNeedParams; this.OrderByExpressioin.NeedParams = bNeedParams; this.GroupByExpression.NeedParams = bNeedParams; this.HavingExpression.NeedParams = bNeedParams; this.TableExpressioin.SplitExpression = this.SplitExpression; this.ColumnsExpressioin.SplitExpression = this.SplitExpression; this.WhereExpressioin.SplitExpression = this.SplitExpression; this.OrderByExpressioin.SplitExpression = this.SplitExpression; this.GroupByExpression.SplitExpression = this.SplitExpression; this.HavingExpression.SplitExpression = this.SplitExpression; }