123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- using Ant.Core;
- using Ant.DbExpressions;
- using Ant.Infrastructure;
- using Ant.ORM;
- using Ant.ORM.Query;
- using Ant.Query.QueryExpressions;
- using Ant.Query.QueryState;
- using Ant.Query.Visitors;
- using Ant.Utility;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- namespace Ant.Query
- {
- class JoiningQuery<T1, T2> : IJoiningQuery<T1, T2>
- {
- AntORM _dbContext;
- QueryBase _rootQuery;
- List<JoiningQueryInfo> _joinedQueries;
- List<LambdaExpression> _filterPredicates;
- public AntORM DbContext { get { return this._dbContext; } }
- public QueryBase RootQuery { get { return this._rootQuery; } }
- public List<JoiningQueryInfo> JoinedQueries { get { return this._joinedQueries; } }
- public List<LambdaExpression> FilterPredicates { get { return this._filterPredicates; } }
- public JoiningQuery(Queryable<T1> q1, Queryable<T2> q2, JoinType joinType, Expression<Func<T1, T2, bool>> on)
- {
- this._dbContext = q1.DbContext;
- this._rootQuery = q1;
- this._joinedQueries = new List<JoiningQueryInfo>(1);
- JoiningQueryInfo joiningQueryInfo = new JoiningQueryInfo(q2, joinType, on);
- this._joinedQueries.Add(joiningQueryInfo);
- this._filterPredicates = new List<LambdaExpression>();
- }
- public JoiningQuery(JoiningQuery<T1, T2> jq, LambdaExpression filterPredicate)
- {
- this._dbContext = jq._dbContext;
- this._rootQuery = jq._rootQuery;
- this._joinedQueries = OrmUtils.Clone(jq._joinedQueries);
- this._filterPredicates = OrmUtils.CloneAndAppendOne(jq._filterPredicates, filterPredicate);
- }
- public IJoiningQuery<T1, T2> Where(Expression<Func<T1, T2, bool>> predicate)
- {
- return new JoiningQuery<T1, T2>(this, predicate);
- }
- public IJoiningQuery<T1, T2, T3> Join<T3>(JoinType joinType, Expression<Func<T1, T2, T3, bool>> on)
- {
- return this.Join<T3>(new Queryable<T3>(this._dbContext), joinType, on);
- }
- public IJoiningQuery<T1, T2, T3> Join<T3>(IQuery<T3> q, JoinType joinType, Expression<Func<T1, T2, T3, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3>(this, (Queryable<T3>)q, joinType, on);
- }
- public IJoiningQuery<T1, T2, T3> InnerJoin<T3>(IQuery<T3> q, Expression<Func<T1, T2, T3, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3>(this, (Queryable<T3>)q, JoinType.InnerJoin, on);
- }
- public IJoiningQuery<T1, T2, T3> LeftJoin<T3>(IQuery<T3> q, Expression<Func<T1, T2, T3, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3>(this, (Queryable<T3>)q, JoinType.LeftJoin, on);
- }
- public IJoiningQuery<T1, T2, T3> RightJoin<T3>(IQuery<T3> q, Expression<Func<T1, T2, T3, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3>(this, (Queryable<T3>)q, JoinType.RightJoin, on);
- }
- public IJoiningQuery<T1, T2, T3> FullJoin<T3>(IQuery<T3> q, Expression<Func<T1, T2, T3, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3>(this, (Queryable<T3>)q, JoinType.FullJoin, on);
- }
- public IJoiningQuery<T1, T2, T3> InnerJoin<T3>(Expression<Func<T1, T2, T3, bool>> on)
- {
- return this.InnerJoin<T3>(new Queryable<T3>(this._dbContext), on);
- }
- public IJoiningQuery<T1, T2, T3> LeftJoin<T3>(Expression<Func<T1, T2, T3, bool>> on)
- {
- return this.LeftJoin<T3>(new Queryable<T3>(this._dbContext), on);
- }
- public IJoiningQuery<T1, T2, T3> RightJoin<T3>(Expression<Func<T1, T2, T3, bool>> on)
- {
- return this.RightJoin<T3>(new Queryable<T3>(this._dbContext), on);
- }
- public IJoiningQuery<T1, T2, T3> FullJoin<T3>(Expression<Func<T1, T2, T3, bool>> on)
- {
- return this.FullJoin<T3>(new Queryable<T3>(this._dbContext), on);
- }
- public IQuery<TResult> Select<TResult>(Expression<Func<T1, T2, TResult>> selector)
- {
- JoinQueryExpression e = new JoinQueryExpression(typeof(TResult), this._rootQuery.QueryExpression, this._joinedQueries, selector);
- return new Queryable<TResult>(this.DbContext, e, this._rootQuery.TrackEntity);
- }
- }
- class JoiningQuery<T1, T2, T3> : IJoiningQuery<T1, T2, T3>
- {
- AntORM _dbContext;
- QueryBase _rootQuery;
- List<JoiningQueryInfo> _joinedQueries;
- List<LambdaExpression> _filterPredicates;
- public AntORM DbContext { get { return this._dbContext; } }
- public QueryBase RootQuery { get { return this._rootQuery; } }
- public List<JoiningQueryInfo> JoinedQueries { get { return this._joinedQueries; } }
- public List<LambdaExpression> FilterPredicates { get { return this._filterPredicates; } }
- public JoiningQuery(JoiningQuery<T1, T2> joiningQuery, Queryable<T3> q, JoinType joinType, Expression<Func<T1, T2, T3, bool>> on)
- {
- //this._dbContext = joiningQuery.DbContext;
- //this._rootQuery = joiningQuery.RootQuery;
- //this._joinedQueries = new List<JoiningQueryInfo>(joiningQuery.JoinedQueries.Count);
- //this._joinedQueries.AddRange(joiningQuery.JoinedQueries);
- //JoiningQueryInfo joiningQueryInfo = new JoiningQueryInfo(q, joinType, on);
- //this._joinedQueries.Add(joiningQueryInfo);
- this._dbContext = joiningQuery.DbContext;
- this._rootQuery = joiningQuery.RootQuery;
- this._joinedQueries = OrmUtils.CloneAndAppendOne(joiningQuery.JoinedQueries, new JoiningQueryInfo(q, joinType, on));
- this._filterPredicates = OrmUtils.Clone(joiningQuery.FilterPredicates);
- }
- public JoiningQuery(JoiningQuery<T1, T2, T3> jq, LambdaExpression filterPredicate)
- {
- this._dbContext = jq._dbContext;
- this._rootQuery = jq._rootQuery;
- this._joinedQueries = OrmUtils.Clone(jq._joinedQueries);
- this._filterPredicates = OrmUtils.CloneAndAppendOne(jq._filterPredicates, filterPredicate);
- }
- public IJoiningQuery<T1, T2, T3> Where(Expression<Func<T1, T2, T3, bool>> predicate)
- {
- return new JoiningQuery<T1, T2, T3>(this, predicate);
- }
- public IJoiningQuery<T1, T2, T3, T4> Join<T4>(JoinType joinType, Expression<Func<T1, T2, T3, T4, bool>> on)
- {
- return this.Join<T4>(new Queryable<T4>(this._dbContext), joinType, on);
- }
- public IJoiningQuery<T1, T2, T3, T4> Join<T4>(IQuery<T4> q, JoinType joinType, Expression<Func<T1, T2, T3, T4, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3, T4>(this, (Queryable<T4>)q, joinType, on);
- }
- public IJoiningQuery<T1, T2, T3, T4> InnerJoin<T4>(IQuery<T4> q, Expression<Func<T1, T2, T3, T4, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3, T4>(this, (Queryable<T4>)q, JoinType.InnerJoin, on);
- }
- public IJoiningQuery<T1, T2, T3, T4> LeftJoin<T4>(IQuery<T4> q, Expression<Func<T1, T2, T3, T4, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3, T4>(this, (Queryable<T4>)q, JoinType.LeftJoin, on);
- }
- public IJoiningQuery<T1, T2, T3, T4> RightJoin<T4>(IQuery<T4> q, Expression<Func<T1, T2, T3, T4, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3, T4>(this, (Queryable<T4>)q, JoinType.RightJoin, on);
- }
- public IJoiningQuery<T1, T2, T3, T4> FullJoin<T4>(IQuery<T4> q, Expression<Func<T1, T2, T3, T4, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3, T4>(this, (Queryable<T4>)q, JoinType.FullJoin, on);
- }
- public IJoiningQuery<T1, T2, T3, T4> InnerJoin<T4>(Expression<Func<T1, T2, T3, T4, bool>> on)
- {
- return this.InnerJoin<T4>(new Queryable<T4>(this._dbContext), on);
- }
- public IJoiningQuery<T1, T2, T3, T4> LeftJoin<T4>(Expression<Func<T1, T2, T3, T4, bool>> on)
- {
- return this.LeftJoin<T4>(new Queryable<T4>(this._dbContext), on);
- }
- public IJoiningQuery<T1, T2, T3, T4> RightJoin<T4>(Expression<Func<T1, T2, T3, T4, bool>> on)
- {
- return this.RightJoin<T4>(new Queryable<T4>(this._dbContext), on);
- }
- public IJoiningQuery<T1, T2, T3, T4> FullJoin<T4>(Expression<Func<T1, T2, T3, T4, bool>> on)
- {
- return this.FullJoin<T4>(new Queryable<T4>(this._dbContext), on);
- }
- public IQuery<TResult> Select<TResult>(Expression<Func<T1, T2, T3, TResult>> selector)
- {
- JoinQueryExpression e = new JoinQueryExpression(typeof(TResult), this._rootQuery.QueryExpression, this._joinedQueries, selector);
- return new Queryable<TResult>(this.DbContext, e, this._rootQuery.TrackEntity);
- }
- }
- class JoiningQuery<T1, T2, T3, T4> : IJoiningQuery<T1, T2, T3, T4>
- {
- AntORM _dbContext;
- QueryBase _rootQuery;
- List<JoiningQueryInfo> _joinedQueries;
- List<LambdaExpression> _filterPredicates;
- public AntORM DbContext { get { return this._dbContext; } }
- public QueryBase RootQuery { get { return this._rootQuery; } }
- public List<JoiningQueryInfo> JoinedQueries { get { return this._joinedQueries; } }
- public List<LambdaExpression> FilterPredicates { get { return this._filterPredicates; } }
- //public JoiningQuery(JoiningQuery<T1, T2, T3> joiningQuery, Queryable<T4> q, JoinType joinType, Expression<Func<T1, T2, T3, T4, bool>> on)
- //{
- // this._dbContext = joiningQuery.DbContext;
- // this._rootQuery = joiningQuery.RootQuery;
- // this._joinedQueries = new List<JoiningQueryInfo>(joiningQuery.JoinedQueries.Count);
- // this._joinedQueries.AddRange(joiningQuery.JoinedQueries);
- // JoiningQueryInfo joiningQueryInfo = new JoiningQueryInfo(q, joinType, on);
- // this._joinedQueries.Add(joiningQueryInfo);
- //}
- public JoiningQuery(JoiningQuery<T1, T2, T3> joiningQuery, Queryable<T4> q, JoinType joinType, Expression<Func<T1, T2, T3, T4, bool>> on)
- {
- this._dbContext = joiningQuery.DbContext;
- this._rootQuery = joiningQuery.RootQuery;
- this._joinedQueries = OrmUtils.CloneAndAppendOne(joiningQuery.JoinedQueries, new JoiningQueryInfo(q, joinType, on));
- this._filterPredicates = OrmUtils.Clone(joiningQuery.FilterPredicates);
- }
- public JoiningQuery(JoiningQuery<T1, T2, T3, T4> jq, LambdaExpression filterPredicate)
- {
- this._dbContext = jq._dbContext;
- this._rootQuery = jq._rootQuery;
- this._joinedQueries = OrmUtils.Clone(jq._joinedQueries);
- this._filterPredicates = OrmUtils.CloneAndAppendOne(jq._filterPredicates, filterPredicate);
- }
- public IJoiningQuery<T1, T2, T3, T4> Where(Expression<Func<T1, T2, T3, T4, bool>> predicate)
- {
- return new JoiningQuery<T1, T2, T3, T4>(this, predicate);
- }
- public IJoiningQuery<T1, T2, T3, T4, T5> Join<T5>(JoinType joinType, Expression<Func<T1, T2, T3, T4, T5, bool>> on)
- {
- return this.Join<T5>(new Queryable<T5>(this._dbContext), joinType, on);
- }
- public IJoiningQuery<T1, T2, T3, T4, T5> Join<T5>(IQuery<T5> q, JoinType joinType, Expression<Func<T1, T2, T3, T4, T5, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3, T4, T5>(this, (Queryable<T5>)q, joinType, on);
- }
- public IJoiningQuery<T1, T2, T3, T4, T5> InnerJoin<T5>(IQuery<T5> q, Expression<Func<T1, T2, T3, T4, T5, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3, T4, T5>(this, (Queryable<T5>)q, JoinType.InnerJoin, on);
- }
- public IJoiningQuery<T1, T2, T3, T4, T5> LeftJoin<T5>(IQuery<T5> q, Expression<Func<T1, T2, T3, T4, T5, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3, T4, T5>(this, (Queryable<T5>)q, JoinType.LeftJoin, on);
- }
- public IJoiningQuery<T1, T2, T3, T4, T5> RightJoin<T5>(IQuery<T5> q, Expression<Func<T1, T2, T3, T4, T5, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3, T4, T5>(this, (Queryable<T5>)q, JoinType.RightJoin, on);
- }
- public IJoiningQuery<T1, T2, T3, T4, T5> FullJoin<T5>(IQuery<T5> q, Expression<Func<T1, T2, T3, T4, T5, bool>> on)
- {
- return new JoiningQuery<T1, T2, T3, T4, T5>(this, (Queryable<T5>)q, JoinType.FullJoin, on);
- }
- public IJoiningQuery<T1, T2, T3, T4, T5> InnerJoin<T5>(Expression<Func<T1, T2, T3, T4, T5, bool>> on)
- {
- return this.InnerJoin<T5>(new Queryable<T5>(this._dbContext), on);
- }
- public IJoiningQuery<T1, T2, T3, T4, T5> LeftJoin<T5>(Expression<Func<T1, T2, T3, T4, T5, bool>> on)
- {
- return this.LeftJoin<T5>(new Queryable<T5>(this._dbContext), on);
- }
- public IJoiningQuery<T1, T2, T3, T4, T5> RightJoin<T5>(Expression<Func<T1, T2, T3, T4, T5, bool>> on)
- {
- return this.RightJoin<T5>(new Queryable<T5>(this._dbContext), on);
- }
- public IJoiningQuery<T1, T2, T3, T4, T5> FullJoin<T5>(Expression<Func<T1, T2, T3, T4, T5, bool>> on)
- {
- return this.FullJoin<T5>(new Queryable<T5>(this._dbContext), on);
- }
- public IQuery<TResult> Select<TResult>(Expression<Func<T1, T2, T3, T4, TResult>> selector)
- {
- JoinQueryExpression e = new JoinQueryExpression(typeof(TResult), this._rootQuery.QueryExpression, this._joinedQueries, selector);
- return new Queryable<TResult>(this.DbContext, e, this._rootQuery.TrackEntity);
- }
- }
- class JoiningQuery<T1, T2, T3, T4, T5> : IJoiningQuery<T1, T2, T3, T4, T5>
- {
- AntORM _dbContext;
- QueryBase _rootQuery;
- List<JoiningQueryInfo> _joinedQueries;
- List<LambdaExpression> _filterPredicates;
- public AntORM DbContext { get { return this._dbContext; } }
- public QueryBase RootQuery { get { return this._rootQuery; } }
- public List<JoiningQueryInfo> JoinedQueries { get { return this._joinedQueries; } }
- public List<LambdaExpression> FilterPredicates { get { return this._filterPredicates; } }
- //老版
- //public JoiningQuery(JoiningQuery<T1, T2, T3, T4> joiningQuery, Queryable<T5> q, JoinType joinType, Expression<Func<T1, T2, T3, T4, T5, bool>> on)
- //{
- // this._dbContext = joiningQuery.DbContext;
- // this._rootQuery = joiningQuery.RootQuery;
- // this._joinedQueries = new List<JoiningQueryInfo>(joiningQuery.JoinedQueries.Count);
- // this._joinedQueries.AddRange(joiningQuery.JoinedQueries);
- // JoiningQueryInfo joiningQueryInfo = new JoiningQueryInfo(q, joinType, on);
- // this._joinedQueries.Add(joiningQueryInfo);
- //}
- //public IQuery<TResult> Select<TResult>(Expression<Func<T1, T2, T3, T4, T5, TResult>> selector)
- //{
- // JoinQueryExpression e = new JoinQueryExpression(typeof(TResult), this._rootQuery.QueryExpression, this._joinedQueries, selector);
- // return new Queryable<TResult>(this.DbContext, e, this._rootQuery.TrackEntity);
- //}
- public JoiningQuery(JoiningQuery<T1, T2, T3, T4> joiningQuery, Queryable<T5> q, JoinType joinType, Expression<Func<T1, T2, T3, T4, T5, bool>> on)
- {
- this._dbContext = joiningQuery.DbContext;
- this._rootQuery = joiningQuery.RootQuery;
- this._joinedQueries = OrmUtils.CloneAndAppendOne(joiningQuery.JoinedQueries, new JoiningQueryInfo(q, joinType, on));
- this._filterPredicates = OrmUtils.Clone(joiningQuery.FilterPredicates);
- }
- public JoiningQuery(JoiningQuery<T1, T2, T3, T4, T5> jq, LambdaExpression filterPredicate)
- {
- this._dbContext = jq._dbContext;
- this._rootQuery = jq._rootQuery;
- this._joinedQueries = OrmUtils.Clone(jq._joinedQueries);
- this._filterPredicates = OrmUtils.CloneAndAppendOne(jq._filterPredicates, filterPredicate);
- }
- public IJoiningQuery<T1, T2, T3, T4, T5> Where(Expression<Func<T1, T2, T3, T4, T5, bool>> predicate)
- {
- return new JoiningQuery<T1, T2, T3, T4, T5>(this, predicate);
- }
- public IQuery<TResult> Select<TResult>(Expression<Func<T1, T2, T3, T4, T5, TResult>> selector)
- {
- if (this._filterPredicates.Count == 0)
- {
- JoinQueryExpression e1 = new JoinQueryExpression(typeof(TResult), this._rootQuery.QueryExpression, this._joinedQueries, selector);
- return new Queryable<TResult>(this.DbContext, e1, this._rootQuery.TrackEntity);
- }
- Type joinResultType = typeof(JoinResult<T1, T2, T3, T4, T5>);
- Expression<Func<T1, T2, T3, T4, T5, JoinResult<T1, T2, T3, T4, T5>>> joinResultSelector = (t1, t2, t3, t4, t5) => new JoinResult<T1, T2, T3, T4, T5>() { Item1 = t1, Item2 = t2, Item3 = t3, Item4 = t4, Item5 = t5 };
- JoinQueryExpression e = new JoinQueryExpression(joinResultType, this._rootQuery.QueryExpression, this._joinedQueries, joinResultSelector);
- IQuery<JoinResult<T1, T2, T3, T4, T5>> q = new Queryable<JoinResult<T1, T2, T3, T4, T5>>(this.DbContext, e, this._rootQuery.TrackEntity);
- ParameterExpression parameter = Expression.Parameter(joinResultType, "a");
- Expression[] expressionSubstitutes = QueryHelper.MakeExpressionSubstitutes(joinResultType, parameter);
- Expression<Func<JoinResult<T1, T2, T3, T4, T5>, bool>> predicate = QueryHelper.ComposePredicate<Func<JoinResult<T1, T2, T3, T4, T5>, bool>>(this._filterPredicates, expressionSubstitutes, parameter);
- var q1 = q.Where(predicate);
- Expression<Func<JoinResult<T1, T2, T3, T4, T5>, TResult>> selector2 = JoinQueryParameterExpressionReplacer.Replace(selector, expressionSubstitutes, parameter) as Expression<Func<JoinResult<T1, T2, T3, T4, T5>, TResult>>;
- var ret = q1.Select(selector2);
- return ret;
- }
-
- }
- }
|