コード例 #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;
            }));
        }
コード例 #2
0
        /// <summary>
        /// 开始建立查询命令对象树.
        /// </summary>
        /// <typeparam name="TEntityAgent">表对应的实体映射代理对象.</typeparam>
        /// <returns></returns>
        internal MultiQuerySelector From <TEntityAgent>() where TEntityAgent : EntityAgent, new()
        {
            sBlock = Command.Select();
            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 了向中添加查询的表.
            EntityTableAttribute tableAttribute = context.GetTableAttribute();

            fBlock.Content.Add(fm.Table(tableAttribute.TableName));
            sBlock.Blocks.Add(fBlock);
            return(this);
        }