Ejemplo n.º 1
0
        /// <summary>
        /// <![CDATA[
        /// 将聚合子表达式解析为嵌入式子查询条件。
        /// 例如:
        /// 将表达式
        /// book.ChapterList.Cast<Chapter>().Any(c => c.Name == chapterName)
        /// 转换为:
        /// f.Exists(f.Query(chapter,
        ///     where: f.And(
        ///         f.Constraint(chapter.Column(Chapter.BookIdProperty), book.IdColumn),
        ///         f.Constraint(chapter.Column(Chapter.NameProperty), chapterName)
        ///     )
        /// ))
        /// SQL:
        /// SELECT * FROM [Book] b
        /// WHERE EXISTS(
        ///     SELECT * FROM [Chapter] c
        ///     WHERE c.BookId = b.Id AND
        ///         c.Name = {0}
        /// )
        /// ]]>
        /// </summary>
        /// <param name="exp">需要解析的表达式</param>
        /// <param name="parentQuery"></param>
        /// <param name="propertyFinder">The property finder.</param>
        internal IConstraint Build(Expression exp, IQuery parentQuery, PropertyFinder propertyFinder)
        {
            _parentQuery          = parentQuery;
            _parentPropertyFinder = propertyFinder;

            this.Visit(exp);

            var res = f.Exists(_query);

            if (!_isAny)
            {
                res = f.Not(res);
            }

            //如果父查询中需要反转条件,则返回 NOT 语句。
            if (propertyFinder.ReverseConstraint)
            {
                res = f.Not(res);
            }

            //把可空外键的不可空条件,与 Exists 条件合并后返回。
            if (propertyFinder.NullableRefConstraint != null)
            {
                var op = propertyFinder.ReverseConstraint ? BinaryOperator.Or : BinaryOperator.And;
                res = f.Binary(propertyFinder.NullableRefConstraint, op, res);
            }

            return(res);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <![CDATA[
        /// 将聚合子表达式解析为嵌入式子查询条件。
        /// 例如:
        /// 将表达式
        /// book.ChapterList.Cast<Chapter>().Any(c => c.Name == chapterName)
        /// 转换为:
        /// f.Exists(f.Query(chapter,
        ///     where: f.And(
        ///         f.Constraint(chapter.Column(Chapter.BookIdProperty), book.IdColumn),
        ///         f.Constraint(chapter.Column(Chapter.NameProperty), chapterName)
        ///     )
        /// ))
        /// SQL:
        /// SELECT * FROM [Book] b
        /// WHERE EXISTS(
        ///     SELECT * FROM [Chapter] c
        ///     WHERE c.BookId = b.Id AND
        ///         c.Name = {0}
        /// )
        /// ]]>
        /// </summary>
        /// <param name="exp">需要解析的表达式</param>
        /// <param name="parentQuery"></param>
        /// <param name="propertyFinder">The property finder.</param>
        internal IConstraint Build(Expression exp, IQuery parentQuery, PropertyFinder propertyFinder)
        {
            _parentQuery = parentQuery;
            _parentPropertyFinder = propertyFinder;

            this.Visit(exp);

            var res = f.Exists(_query);
            if (!_isAny) res = f.Not(res);

            //如果父查询中需要反转条件,则返回 NOT 语句。
            if (propertyFinder.ReverseConstraint)
            {
                res = f.Not(res);
            }

            //把可空外键的不可空条件,与 Exists 条件合并后返回。
            if (propertyFinder.NullableRefConstraint != null)
            {
                var op = propertyFinder.ReverseConstraint ? BinaryOperator.Or : BinaryOperator.And;
                res = f.Binary(propertyFinder.NullableRefConstraint, op, res);
            }

            return res;
        }