Exemplo n.º 1
0
        internal void AddInnerRelation(Type inner, string condition)
        {
            if (__Relations.ContainsKey(inner))
            {
                throw new CRLException(string.Format("关联查询已包含关联对象 {0} {1}", inner, condition));
                return;
            }
            if (__MainType == inner)
            {
                throw new CRLException(string.Format("关联查询不能指定自已 {0} {1}", inner, condition));
                return;
            }
            DBExtendFactory.CreateDBExtend(__DbContext).CheckTableCreated(inner);
            var tableName = TypeCache.GetTableName(inner, __DbContext);

            string aliasName = GetPrefix(inner);
            var    joinType  = __JoinTypes[inner];

            tableName = string.Format("{0} {1} ", __DBAdapter.KeyWordFormat(tableName), aliasName.Substring(0, aliasName.Length - 1));
            string str = string.Format(" {0} join {1} on {2}", joinType, tableName + " " + __DBAdapter.GetWithNolockFormat(),
                                       condition);

            if (!__Relations.ContainsKey(inner))
            {
                __Relations.Add(inner, str);
            }
        }
Exemplo n.º 2
0
        //internal void AddInnerRelationCondition(TypeQuery inner, string condition)
        //{
        //    __Relations[inner] += "  and " + condition;
        //}
        internal void AddInnerRelation(TypeQuery typeQuery, JoinType joinType, string condition)
        {
            if (__Relations == null)
            {
                __Relations = new Dictionary <TypeQuery, JoinInfo>();
            }
            var inner = typeQuery.OriginType;

            if (__Relations.ContainsKey(typeQuery))
            {
                throw new CRLException(string.Format("关联查询已包含关联对象 {0} {1}", inner, condition));
                return;
            }
            //if (__MainType == inner)
            //{
            //    throw new CRLException(string.Format("关联查询不能指定自已 {0} {1}" , inner,condition));
            //    return;
            //}
            if (inner.IsSubclassOf(typeof(IModel)))
            {
                DBExtendFactory.CreateDBExtend(__DbContext).CheckTableCreated(inner);
            }
            var tableName = TypeCache.GetTableName(inner, __DbContext);

            string aliasName = GetPrefix(inner);

            aliasName = aliasName.Substring(0, aliasName.Length - 1);
            if (typeQuery.TypeQueryEnum == TypeQueryEnum.查询)
            {
                //查询别名按关联别名算
                condition = condition.Replace(typeQuery.queryName2, aliasName + ".");
                tableName = string.Format("({0}) {1} ", typeQuery.InnerQuery, aliasName);
            }
            else
            {
                tableName = string.Format("{0} {1} {2}", __DBAdapter.KeyWordFormat(tableName), aliasName, __DBAdapter.GetWithNolockFormat(__WithNoLock));
            }
            //string str = string.Format(" {0} join {1} on {2}", joinType, tableName, condition);
            if (!__Relations.ContainsKey(typeQuery))
            {
                var join = new JoinInfo()
                {
                    joinType = joinType, tableName = tableName, condition = condition
                };
                __Relations.Add(typeQuery, join);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_DBAdapter"></param>
        /// <param name="usePrefix">是否使用字段前辍 如 t1.Name</param>
        /// <param name="withTablePrefix">是否生按表生成前辍,关联时用 如Table__Name</param>
        /// <param name="mapingName">别名,空则按字段名,没有AS</param>
        /// <param name="fieldName">自定义查询字段名,空则按Name</param>
        internal void SetFieldQueryScript2(DBAdapter.DBAdapterBase _DBAdapter, string usePrefix, bool withTablePrefix, string mapingName, string fieldName = "")
        {
            string query = "";

            if (!string.IsNullOrEmpty(usePrefix))
            {
                //query += "{" + ModelType.FullName + "}";
                query += usePrefix;
            }
            if (string.IsNullOrEmpty(fieldName))
            {
                fieldName = withTablePrefix ? MapingName : _DBAdapter.KeyWordFormat(MapingName);
            }
            //判断虚拟字段
            if (FieldType == Attribute.FieldType.虚拟字段)
            {
                query      = VirtualField.Replace("{" + ModelType.FullName + "}", usePrefix);//替换前辍
                mapingName = MemberName;
            }
            else
            {
                query += fieldName;
            }
            QueryField = query;
            var mappNameFull = fieldName;

            if (!string.IsNullOrEmpty(mapingName))
            {
                //MapingName = mapingName;
                mappNameFull = mapingName;
            }
            if (withTablePrefix)
            {
                mappNameFull = GetTableFieldFormat(TableName, mappNameFull);
            }
            //MapingName = mappNameFull;
            //别名不为空或有表前辍
            if (!string.IsNullOrEmpty(mapingName) || withTablePrefix)
            {
                QueryFullScript = string.Format("{0} as {1}", query, mappNameFull);
            }
            else
            {
                QueryFullScript = query;
            }
        }
Exemplo n.º 4
0
 string FormatFieldPrefix(Type type, string fieldName)
 {
     return(Prefixs[type] + __DBAdapter.KeyWordFormat(fieldName));
 }