示例#1
0
        /// <summary>
        /// 根据指定类型<see cref="DbGroupByExpression"/>表达式创建虚拟数据源列表语句片段。
        /// </summary>
        /// <param name="context">生成上下文。</param>
        /// <param name="source">虚拟数据源</param>
        /// <returns>查询语句片段。</returns>
        public virtual SelectFragment CreateVirtualListForGroupBy(GenerateContext context, VirtualSourceFragment source)
        {
            var content = (DbGroupByExpression)source.Expression;
            var target  = source.Source;

            var body      = source.GetBody();
            var list      = new SelectFragment(context, target);
            var container = source.Container;

            if (container.IsRecommandLock)
            {
                container = container.Parent as SelectFragment;
            }
            container.AddSource(list);
            list.RetrievalMembers(content.Source.Item, false);

            list.Join      = EJoinType.InnerJoin;
            list.Condition = body.Members.OfType <ReferenceMemberFragment>().Select(member =>
            {
                var left = list.Members.OfType <ReferenceMemberFragment>().Where(a => a.Reference == member.Reference).Single();
                return(new BinaryFragment(context, EBinaryKind.Equal)
                {
                    Left = left,
                    Right = ValidateMember(context, member, container, null, true)
                });
            }).Merge();
            return(list);
        }
示例#2
0
        /// <summary>
        /// 根据指定类型<see cref="DbCollectionMemberExpression"/>表达式创建虚拟数据源列表语句片段。
        /// </summary>
        /// <param name="context">生成上下文。</param>
        /// <param name="source">虚拟数据源</param>
        /// <returns>查询语句片段。</returns>
        public virtual SelectFragment CreateVirtualListForCollectionMember(GenerateContext context, VirtualSourceFragment source)
        {
            var content   = (DbCollectionMemberExpression)source.Expression;
            var target    = GetSource(context, content.TargetSet.Item);
            var container = source.Container;

            if (container.IsRecommandLock)
            {
                container = container.Parent as SelectFragment;
            }
            var list = new SelectFragment(context, target);

            if (content.Metadata.IsComposite)
            {
                GenerateVirtualCompositeJoinForCollectionMember(context, content, list, true);
            }
            container.AddSource(list);

            GenerateVirtualJoinForCollectionMember(context, source, list, false);
            list.RetrievalMembers(content.TargetSet.Item, false);
            if (IsSelectFragment(content))
            {
                context.RegisterTempSource(content.Item, target, delegate()
                {
                    list = InitialSelectFragment(list, content);
                });
            }
            return(list);
        }
示例#3
0
        /// <summary>
        /// 根据指定类型<see cref="DbGroupJoinExpression"/>表达式创建虚拟数据源列表语句片段。
        /// </summary>
        /// <param name="context">生成上下文。</param>
        /// <param name="source">虚拟数据源</param>
        /// <returns>查询语句片段。</returns>
        public virtual SelectFragment CreateVirtualListForGroupJoin(GenerateContext context, VirtualSourceFragment source)
        {
            var content = (DbGroupJoinExpression)source.Expression;
            var target  = GetSource(context, content.Target.Item);

            var list      = new SelectFragment(context, target);
            var container = source.Container;

            if (container.IsRecommandLock)
            {
                container = container.Parent as SelectFragment;
            }
            container.AddSource(list);

            list.Join      = EJoinType.LeftJoin;
            list.Condition = content.KeyPairs.Select(a => container.CreateExpression(a)).Merge();
            list.RetrievalMembers(content.Target.Item, false);
            return(list);
        }
示例#4
0
        /// <summary>
        /// 根据指定类型<see cref="DbGroupByExpression"/>表达式创建数据源语句片段。
        /// </summary>
        /// <param name="context">生成上下文。</param>
        /// <param name="expression">指定表达式。</param>
        /// <returns>创建结果。</returns>
        protected virtual ISourceFragment CreateSourceForGroupBy(GenerateContext context, DbExpression expression)
        {
            var content   = (DbGroupByExpression)expression;
            var groupitem = (DbGroupItemExpression)content.Item;
            var source    = CreateSource(context, content.Source);
            var body      = new SelectFragment(context, source);

            body.RetrievalMembers(content.Key, false);
            foreach (var member in body.Members.OfType <ReferenceMemberFragment>())
            {
                body.GroupBys.Add(member.Reference);
            }
            var container     = new SelectFragment(context, body);
            var virtualSource = new VirtualSourceFragment(context, expression, container, source, body);

            context.RegisterSource(content, virtualSource);
            context.RegisterSource(content.Item, virtualSource);
            return(container);
        }