internal void AddInnerRelation(TypeQuery typeQuery, JoinType joinType, string condition) { 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()); } string str = string.Format(" {0} join {1} on {2}", joinType, tableName, condition); if (!__Relations.ContainsKey(typeQuery)) { __Relations.Add(typeQuery, str); } }
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); } }