Exemplo n.º 1
0
        /// <summary>
        /// mongodb专用
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public LambdaQueryResultSelect <TResult> HavingCount(Expression <Func <TResult, bool> > expression)
        {
            BaseQuery.GetPrefix(typeof(TResult));
            var crlExpression = BaseQuery.__Visitor.RouteExpressionHandler(expression.Body);

            BaseQuery.mongoHavingCount = crlExpression;
            return(this);
        }
        /// <summary>
        /// 返回强类型结果选择
        /// </summary>
        /// <param name="resultSelector"></param>
        /// <returns></returns>
        public ILambdaQueryResultSelect <TJoinResult2> Select <TJoinResult2>(Expression <Func <T, TJoinResult, TJoinResult2> > resultSelector)
            where TJoinResult2 : class
        {
            var parameters   = resultSelector.Parameters.Select(b => b.Type).ToArray();
            var selectField  = BaseQuery.GetSelectField(true, resultSelector.Body, false, parameters);
            var resultFields = selectField.mapping;
            var prefix1      = BaseQuery.GetPrefix(typeof(TJoinResult));
            var prefix2      = BaseQuery.GetPrefix(resultSelect.InnerType);

            //替换匿名前辍
            foreach (var item in resultFields)
            {
                if (item.QueryFull.Contains(prefix1))
                {
                    item.QueryFull = item.QueryFull.Replace(prefix1, prefix2);
                }
            }

            BaseQuery.SetSelectFiled(selectField);

            return(new LambdaQueryResultSelect <TJoinResult2>(BaseQuery, resultSelector.Body));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 在当前关联基础上再创建关联
        /// </summary>
        /// <typeparam name="TJoin2">再关联的类型</typeparam>
        /// <param name="expression">关联语法</param>
        /// <param name="joinType">关联类型</param>
        /// <returns></returns>
        public LambdaQueryJoin <TJoin, TJoin2> Join <TJoin2>(Expression <Func <TJoin, TJoin2, bool> > expression, JoinType joinType = JoinType.Inner) where TJoin2 : IModel, new()
        {
            //like
            //query.Join<Code.Member>((a, b) => a.UserId == b.Id)
            //    .Select((a, b) => new { a.BarCode, b.Name })
            //    .Join<Code.Order>((a, b) => a.Id == b.Id);
            var query2    = new LambdaQueryJoin <TJoin, TJoin2>(BaseQuery);
            var innerType = typeof(TJoin2);

            //BaseQuery.__JoinTypes.Add(new TypeQuery(innerType), joinType);
            BaseQuery.GetPrefix(innerType);
            string condition = BaseQuery.FormatJoinExpression(expression.Body);

            BaseQuery.AddInnerRelation(new TypeQuery(innerType), joinType, condition);
            return(query2);
        }