From a2a4bbd349b2c7995f260e081ec596a80c7b309f Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Mon, 19 Jun 2017 12:16:51 +0800 Subject: [PATCH] The Join section can write the conditions --- SqlServerTest/Demos/1_Query.cs | 7 +++++++ SqlSugar/SqlSugarAccessory.cs | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/SqlServerTest/Demos/1_Query.cs b/SqlServerTest/Demos/1_Query.cs index 6f0a172aa..9041108f1 100644 --- a/SqlServerTest/Demos/1_Query.cs +++ b/SqlServerTest/Demos/1_Query.cs @@ -229,6 +229,13 @@ namespace OrmTest.Demo .OrderBy((st, sc) => sc.Id, OrderByType.Desc) .Select((st, sc) => new ViewModelStudent { Name = st.Name, SchoolId = sc.Id }).ToList(); + + //join 2 + var list4_1 = db.Queryable((st, sc) => new object[] { + JoinType.Left,st.SchoolId==sc.Id&& st.Name == "jack" + }).ToList(); + + //The simple use of Join 2 table var list5 = db.Queryable((st, sc) => st.SchoolId == sc.Id).Select((st,sc)=>new {st.Name,st.Id,schoolName=sc.Name}).ToList(); diff --git a/SqlSugar/SqlSugarAccessory.cs b/SqlSugar/SqlSugarAccessory.cs index eccc05695..8d78b2682 100644 --- a/SqlSugar/SqlSugarAccessory.cs +++ b/SqlSugar/SqlSugarAccessory.cs @@ -181,8 +181,12 @@ namespace SqlSugar { this.CreateQueryable(queryable); string shortName = string.Empty; - queryable.SqlBuilder.QueryBuilder.JoinQueryInfos = this.GetJoinInfos(joinExpression, ref shortName, types); + List paramters =new List(); + queryable.SqlBuilder.QueryBuilder.JoinQueryInfos = this.GetJoinInfos(joinExpression,ref paramters, ref shortName, types); queryable.SqlBuilder.QueryBuilder.TableShortName = shortName; + if (paramters != null) { + queryable.SqlBuilder.QueryBuilder.Parameters.AddRange(paramters); + } } protected void CreateEasyQueryJoin(Expression joinExpression, Type[] types, ISugarQueryable queryable) where T : class, new() { @@ -194,7 +198,7 @@ namespace SqlSugar #endregion #region Private methods - protected List GetJoinInfos(Expression joinExpression, ref string shortName, params Type[] entityTypeArray) + protected List GetJoinInfos(Expression joinExpression,ref List parameters, ref string shortName, params Type[] entityTypeArray) { List result = new List(); var lambdaParameters = ((LambdaExpression)joinExpression).Parameters.ToList(); @@ -204,6 +208,7 @@ namespace SqlSugar expressionContext.Resolve(joinExpression, ResolveExpressType.Join); int i = 0; var joinArray = expressionContext.Result.GetResultArray(); + parameters = expressionContext.Parameters; foreach (var entityType in entityTypeArray) { var isFirst = i == 0; ++i;