From 422b4c2b5895affc9949f73d794b54f3d239cff0 Mon Sep 17 00:00:00 2001 From: sunkaixuan <610262374@qq.com> Date: Fri, 26 May 2017 02:25:26 +0800 Subject: [PATCH] - --- OrmTest/Demo/Query.cs | 9 +++++++-- SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs | 1 + .../Abstract/InsertableProvider/InsertableProvider.cs | 1 + SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs | 4 +++- SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs | 1 + SqlSugar/ExpressionsToSql/Method/NBORM.cs | 8 ++++---- SqlSugar/SqlSugarClient.cs | 4 ++-- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/OrmTest/Demo/Query.cs b/OrmTest/Demo/Query.cs index b03cea966..775c67ddb 100644 --- a/OrmTest/Demo/Query.cs +++ b/OrmTest/Demo/Query.cs @@ -64,6 +64,9 @@ namespace OrmTest.Demo var isAny = db.Queryable().Where(it=>it.Id==-1).Any(); var isAny2 = db.Queryable().Any(it => it.Id == -1); var getListByRename = db.Queryable().AS("Student").ToList(); + var group = db.Queryable().GroupBy(it => it.Id) + .Having(it => NBORM.AggregateCount(it.Id) > 10) + .Select(it =>new { id = NBORM.AggregateCount(it.Id) }).ToList(); } public static void Page() @@ -115,13 +118,15 @@ namespace OrmTest.Demo //join 2 var list = db.Queryable((st, sc) => new object[] { JoinType.Left,st.SchoolId==sc.Id - }).ToList(); + }) + .Where(st=>st.Name=="jack").ToList(); //join 3 var list2 = db.Queryable((st, sc,st2) => new object[] { JoinType.Left,st.SchoolId==sc.Id, JoinType.Left,st.SchoolId==st2.Id - }).ToList(); + }) + .Where((st, sc, st2)=> st2.Id==1||sc.Id==1||st.Id==1).ToList(); //join return List var list3 = db.Queryable((st, sc) => new object[] { diff --git a/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs b/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs index 7e2460e26..b69e80a6c 100644 --- a/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs +++ b/SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs @@ -34,6 +34,7 @@ namespace SqlSugar { var entityName = typeof(T).Name; IsAs = true; + OldMappingTableList = this.Context.MappingTables; this.Context.MappingTables = this.Context.RewritableMethods.TranslateCopy(this.Context.MappingTables); this.Context.MappingTables.Add(entityName, tableName); return this; ; diff --git a/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index e8aa8b30a..d4c67ae99 100644 --- a/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -60,6 +60,7 @@ namespace SqlSugar { var entityName = typeof(T).Name; IsAs = true; + OldMappingTableList = this.Context.MappingTables; this.Context.MappingTables = this.Context.RewritableMethods.TranslateCopy(this.Context.MappingTables); this.Context.MappingTables.Add(entityName, tableName); return this; ; diff --git a/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 840cb6cd0..6dfeb9f10 100644 --- a/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -250,6 +250,7 @@ namespace SqlSugar { var entityName = typeof(T2).Name; IsAs = true; + OldMappingTableList = this.Context.MappingTables; this.Context.MappingTables = this.Context.RewritableMethods.TranslateCopy(this.Context.MappingTables); this.Context.MappingTables.Add(entityName, tableName); return this; @@ -258,6 +259,7 @@ namespace SqlSugar { var entityName = typeof(T).Name; IsAs = true; + OldMappingTableList = this.Context.MappingTables; this.Context.MappingTables = this.Context.RewritableMethods.TranslateCopy(this.Context.MappingTables); this.Context.MappingTables.Add(entityName, tableName); return this; @@ -756,7 +758,7 @@ namespace SqlSugar { if (IsAs) { - this.Context.MappingTables = OldMappingTableList; + this.Context.MappingTables = OldMappingTableList==null?new MappingTableList():OldMappingTableList; } } #endregion diff --git a/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs b/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs index e40d207a2..b9eb2e907 100644 --- a/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs +++ b/SqlSugar/Abstract/UpdateProvider/UpdateableProvider.cs @@ -35,6 +35,7 @@ namespace SqlSugar { var entityName = typeof(T).Name; IsAs = true; + OldMappingTableList = this.Context.MappingTables; this.Context.MappingTables = this.Context.RewritableMethods.TranslateCopy(this.Context.MappingTables); this.Context.MappingTables.Add(entityName, tableName); return this; ; diff --git a/SqlSugar/ExpressionsToSql/Method/NBORM.cs b/SqlSugar/ExpressionsToSql/Method/NBORM.cs index 6be6e8f9a..348514ad8 100644 --- a/SqlSugar/ExpressionsToSql/Method/NBORM.cs +++ b/SqlSugar/ExpressionsToSql/Method/NBORM.cs @@ -34,10 +34,10 @@ namespace SqlSugar public static string Substring(object value, int index, int length) { throw new NotImplementedException(); } public static string Replace(object value,string oldChar, string newChar) { throw new NotImplementedException(); } public static int Length(object value) { throw new NotImplementedException(); } - public static dynamic AggregateSum(object thisValue) { throw new NotImplementedException(); } + public static TResult AggregateSum(TResult thisValue) { throw new NotImplementedException(); } public static TResult AggregateAvg(TResult thisValue) { throw new NotImplementedException(); } - public static dynamic AggregateMin(object thisValue) { throw new NotImplementedException(); } - public static dynamic AggregateMax(object thisValue) { throw new NotImplementedException(); } - public static dynamic AggregateCount(object thisValue) { throw new NotImplementedException(); } + public static TResult AggregateMin(TResult thisValue) { throw new NotImplementedException(); } + public static TResult AggregateMax(TResult thisValue) { throw new NotImplementedException(); } + public static TResult AggregateCount(TResult thisValue) { throw new NotImplementedException(); } } } diff --git a/SqlSugar/SqlSugarClient.cs b/SqlSugar/SqlSugarClient.cs index f2dd8be47..b856a7e5e 100644 --- a/SqlSugar/SqlSugarClient.cs +++ b/SqlSugar/SqlSugarClient.cs @@ -166,7 +166,7 @@ namespace SqlSugar queryable.SqlBuilder.QueryBuilder.TableShortName = shortName; return queryable; } - public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() { var queryable = InstanceFactory.GetQueryable(base.CurrentConnectionConfig); base.CreateQueryable(queryable); @@ -175,7 +175,7 @@ namespace SqlSugar queryable.SqlBuilder.QueryBuilder.TableShortName = shortName; return queryable; } - public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() + public virtual ISugarQueryable Queryable(Expression> joinExpression) where T : class, new() { var queryable = InstanceFactory.GetQueryable(base.CurrentConnectionConfig); base.CreateQueryable(queryable);