Exemplo n.º 1
0
        private FromSection <T> Join <TJoin>(TableRelation <TJoin> relation, string aliasName, WhereClip onWhere, JoinType joinType)
            where TJoin : Entity
        {
            //将TableRelation的对象添加到当前节
            this.entities.AddRange(relation.GetFromSection().TableEntities);

            TJoin entity = CoreHelper.CreateInstance <TJoin>();
            var   table  = entity.GetTable().As(aliasName);

            if ((IField)query.PagingField == null)
            {
                //标识列和主键优先,包含ID的列被抛弃
                query.SetPagingField(entity.PagingField);
            }

            string tableName = entity.GetTable().Name;

            if (aliasName != null)
            {
                tableName = aliasName;
            }

            //处理tableRelation关系
            string joinString = "(" + relation.GetFromSection().Query.QueryString + ") " + tableName;

            this.query.Parameters = relation.GetFromSection().Query.Parameters;

            string strJoin = string.Empty;

            if (onWhere != null)
            {
                strJoin = " ON " + onWhere.ToString();
            }

            //获取关联方式
            string join = GetJoinEnumString(joinType);

            if (this.relation != null)
            {
                this.tableName = " __[[ " + this.tableName;
                this.relation += " ]]__ ";
            }
            this.relation += join + joinString + strJoin;

            return(this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 返回一个Query节
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public QuerySection <T> From <T>(TableRelation <T> relation)
            where T : Entity
        {
            //重新实例化一个Query
            var query = new QuerySection <T>(relation.GetFromSection(), dbProvider, this);

            //处理前n条
            if (relation.GetTopSize() > 0)
            {
                query = query.GetTop(relation.GetTopSize());
            }

            return(query);
        }