Exemple #1
0
        /// <summary>
        /// 向多表查询中添加一个联合查询的表.
        /// </summary>
        /// <typeparam name="TEntityAgent">表的实体映射代理对象.</typeparam>
        /// <returns></returns>
        public EntityJoinSelector Join <TEntityAgent>() where TEntityAgent : EntityAgent, new()
        {
            if (sBlock == null)
            {
                throw new NullReferenceException("Please invoke in advance the \"From\" method.");
            }
            TEntityAgent agent   = new TEntityAgent();
            TableMapper  context = agent.CreateContext();

            context.SetDataEngine(ReadEngine, null);
            agent.TableContext     = context;
            agent.IncludeTableName = true;  // 指法查询代理对象在生成字段信息时带上表名.
            // 将实体表的代理类记录下来,后面组织查询时还要用到.
            if (!(AgentsIndexes.ContainsKey(typeof(TEntityAgent))))
            {
                AgentBufferItem BufferItem = new AgentBufferItem(agent);
                AgentsIndexes.Add(typeof(TEntityAgent), BufferItem);
                Agents.Add(BufferItem);
            }
            // 向 FROM 子向中添加 LEFT JOIN 子句.
            EntityTableAttribute tableAttribute = context.GetTableAttribute();
            LeftJoinDescription  leftJoin       = fm.LeftJoin(fm.Table(tableAttribute.TableName));

            fBlock.Content.Add(leftJoin);
            // 返回 JEFT JOIN 子句的筛选器构建对象.
            return(new EntityJoinSelector(this, leftJoin, (t) => {
                if (AgentsIndexes.ContainsKey(t))
                {
                    return AgentsIndexes[t].Agent <EntityAgent>();
                }
                return null;
            }));
        }
Exemple #2
0
        /// <summary>
        /// 解释 LEFT JOIN 子句。
        /// </summary>
        /// <param name="DbParameters">用于缓存在解释过程中可能会产生的参数。</param>
        /// <returns></returns>
        public override string Parsing(ref List <IDbDataParameter> DbParameters)
        {
            LeftJoinDescription LeftJoin = (LeftJoinDescription)this.Description;
            StringBuilder       cBuffer  = new StringBuilder(" LEFT JOIN");

            LeftJoin.Table.DescriptionParserAdapter = LeftJoin.DescriptionParserAdapter;
            cBuffer.Append(LeftJoin.Table.GetParser().Parsing(ref DbParameters));
            cBuffer.Append(" ON");
            ExpDescription ExpDes = (ExpDescription)LeftJoin.OnDescription[0];

            ExpDes.DescriptionParserAdapter = LeftJoin.DescriptionParserAdapter;
            cBuffer.Append(ExpDes.GetParser().Parsing(ref DbParameters));
            if (LeftJoin.OnDescription.Count > 1)
            {
                for (int i = 1; i < LeftJoin.OnDescription.Count; ++i)
                {
                    ExpDes = (ExpDescription)LeftJoin.OnDescription[i];
                    ExpDes.DescriptionParserAdapter = LeftJoin.DescriptionParserAdapter;
                    cBuffer.AppendFormat(" {0} {1}", KeywordsAnd, ExpDes.GetParser().Parsing(ref DbParameters));
                }
            }
            return(cBuffer.ToString());
        }
Exemple #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="leftJion"></param>
 /// <param name="getAgent"></param>
 internal EntityJoinSelector(MultiQuerySelector owner, LeftJoinDescription leftJion, Func <Type, EntityAgent> getAgent)
 {
     _Owner         = owner;
     LeftJion       = leftJion;
     GetTargetAgent = getAgent;
 }