Exemple #1
0
        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);
        }
Exemple #2
0
        /// <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);
        }
Exemple #4
0
        /// <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;
        }