From d2e8bcc26b4397fe7d6add4776139a69cf9d988a Mon Sep 17 00:00:00 2001 From: 28810 <28810@YEXIANGQIN> Date: Sun, 26 Apr 2020 13:45:23 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=20IncludeMany=20?= =?UTF-8?q?=E9=9B=86=E5=90=88=E5=B1=9E=E6=80=A7=E4=B8=BA=20a.xx.Childs=20?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E9=94=99?= =?UTF-8?q?=E8=AF=AF=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MsAccess/Curd/MsAccessSelectTest.cs | 5 + FreeSql/FreeSql.xml | 306 ++++++++++-------- .../SelectProvider/Select1Provider.cs | 21 +- 3 files changed, 185 insertions(+), 147 deletions(-) diff --git a/FreeSql.Tests/FreeSql.Tests/MsAccess/Curd/MsAccessSelectTest.cs b/FreeSql.Tests/FreeSql.Tests/MsAccess/Curd/MsAccessSelectTest.cs index 09682b77..8a51a097 100644 --- a/FreeSql.Tests/FreeSql.Tests/MsAccess/Curd/MsAccessSelectTest.cs +++ b/FreeSql.Tests/FreeSql.Tests/MsAccess/Curd/MsAccessSelectTest.cs @@ -1087,17 +1087,20 @@ WHERE (((cstr(a.[Id])) in (SELECT b.[Title] var t00 = g.msaccess.Select() .IncludeMany(a => a.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2id)) .Where(a => a.model2id <= model1.id) + .Limit(10) .ToList(); var t11 = g.msaccess.Select() .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id)) .Where(a => a.id <= model1.id) + .Limit(10) .ToList(); var t22 = g.msaccess.Select() .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2111Idaaa == a.model2.model2id), then => then.IncludeMany(m3 => m3.childs2.Take(2).Where(m4 => m4.model3333Id333 == m3.id))) .Where(a => a.id <= model1.id) + .Limit(10) .ToList(); } @@ -1148,12 +1151,14 @@ WHERE (((cstr(a.[Id])) in (SELECT b.[Title] .LeftJoin(a => a.model2id == a.model2.id) .IncludeMany(a => a.model2.childs.Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting)) .Where(a => a.id <= model1.id) + .Limit(10) .ToList(true); var t11 = g.msaccess.Select() .LeftJoin(a => a.model2id == a.model2.id) .IncludeMany(a => a.model2.childs.Take(1).Where(m3 => m3.model2Id == a.model2.id && m3.setting == a.m3setting)) .Where(a => a.id <= model1.id) + .Limit(10) .ToList(true); } diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index d6b6f1a8..b9f10e13 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -2310,137 +2310,6 @@ - - - 查询,若使用读写分离,查询【从库】条件cmdText.StartsWith("SELECT "),否则查询【主库】 - - - - - - - - - 查询,ExecuteReaderAsync(dr => {}, "select * from user where age > ?age", new { age = 25 }) - - - - - - - 查询 - - - - - - - 查询,ExecuteArrayAsync("select * from user where age > ?age", new { age = 25 }) - - - - - - - - 查询 - - - - - - - 查询,ExecuteDataSetAsync("select * from user where age > ?age; select 2", new { age = 25 }) - - - - - - - - 查询 - - - - - - - 查询,ExecuteDataTableAsync("select * from user where age > ?age", new { age = 25 }) - - - - - - - - 在【主库】执行 - - - - - - - - 在【主库】执行,ExecuteNonQueryAsync("delete from user where age > ?age", new { age = 25 }) - - - - - - - - 在【主库】执行 - - - - - - - - 在【主库】执行,ExecuteScalarAsync("select 1 from user where age > ?age", new { age = 25 }) - - - - - - - - 执行SQL返回对象集合,QueryAsync<User>("select * from user where age > ?age", new SqlParameter { ParameterName = "age", Value = 25 }) - - - - - - - - - - 执行SQL返回对象集合,QueryAsync<User>("select * from user where age > ?age", new { age = 25 }) - - - - - - - - - 执行SQL返回对象集合,Query<User>("select * from user where age > ?age; select * from address", new SqlParameter { ParameterName = "age", Value = 25 }) - - - - - - - - - - 执行SQL返回对象集合,Query<User>("select * from user where age > ?age; select * from address", new { age = 25 }) - - - - - - 可自定义解析表达式 @@ -2961,12 +2830,6 @@ 超时 - - - 获取资源 - - - 使用完毕后,归还资源 @@ -3037,12 +2900,6 @@ 资源对象 - - - 从对象池获取对象成功的时候触发,通过该方法统计或初始化对象 - - 资源对象 - 归还对象给对象池的时候触发 @@ -3675,4 +3532,167 @@ + + + + + + 使用 or 拼接两个 lambda 表达式 + + + + + + 使用 or 拼接两个 lambda 表达式 + + + true 时生效 + + + + + + 将 lambda 表达式取反 + + + true 时生效 + + + + + 生成类似Mongodb的ObjectId有序、不重复Guid + + + + + + 插入数据 + + + + + + + 插入数据,传入实体 + + + + + + + + 插入数据,传入实体数组 + + + + + + + + 插入数据,传入实体集合 + + + + + + + + 插入数据,传入实体集合 + + + + + + + + 修改数据 + + + + + + + 修改数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1} + + + 主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合 + + + + + 查询数据 + + + + + + + 查询数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1} + + + 主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合 + + + + + 删除数据 + + + + + + + 删除数据,传入动态对象如:主键值 | new[]{主键值1,主键值2} | TEntity1 | new[]{TEntity1,TEntity2} | new{id=1} + + + 主键值、主键值集合、实体、实体集合、匿名对象、匿名对象集合 + + + + + 开启事务(不支持异步),60秒未执行完成(可能)被其他线程事务自动提交 + + 事务体 () => {} + + + + 开启事务(不支持异步) + + 超时,未执行完成(可能)被其他线程事务自动提交 + 事务体 () => {} + + + + 开启事务(不支持异步) + + + 事务体 () => {} + 超时,未执行完成(可能)被其他线程事务自动提交 + + + + 数据库访问对象 + + + + + 所有拦截方法都在这里 + + + + + CodeFirst 模式开发相关方法 + + + + + DbFirst 模式开发相关方法 + + + + + 全局过滤设置,可默认附加为 Select/Update/Delete 条件 + + + diff --git a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs index 3870966f..f75af392 100644 --- a/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs +++ b/FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs @@ -528,14 +528,22 @@ namespace FreeSql.Internal.CommonProvider var getListValue1 = membersExpNotNull == null ? Expression.Lambda>( Expression.Block( - Expression.Return(returnTarget, Expression.Call(null, GetEntityValueWithPropertyNameMethod, Expression.Constant(_orm), Expression.Constant(membersExp.Type), membersExp, propertyNameExp)), + Expression.IfThenElse( + Expression.Equal(propertyNameExp, Expression.Constant("")), //propertyName == "" 返回自身 + Expression.Return(returnTarget, membersExp), + Expression.Return(returnTarget, Expression.Call(null, GetEntityValueWithPropertyNameMethod, Expression.Constant(_orm), Expression.Constant(membersExp.Type), membersExp, propertyNameExp)) + ), Expression.Label(returnTarget, Expression.Default(typeof(object))) ), t1parm, propertyNameExp).Compile() : Expression.Lambda>( Expression.Block( Expression.IfThen( membersExpNotNull, - Expression.Return(returnTarget, Expression.Call(null, GetEntityValueWithPropertyNameMethod, Expression.Constant(_orm), Expression.Constant(membersExp.Type), membersExp, propertyNameExp)) + Expression.IfThenElse( + Expression.Equal(propertyNameExp, Expression.Constant("")), + Expression.Return(returnTarget, membersExp), + Expression.Return(returnTarget, Expression.Call(null, GetEntityValueWithPropertyNameMethod, Expression.Constant(_orm), Expression.Constant(membersExp.Type), membersExp, propertyNameExp)) + ) ), Expression.Label(returnTarget, Expression.Default(typeof(object))) ), t1parm, propertyNameExp).Compile(); @@ -656,7 +664,7 @@ namespace FreeSql.Internal.CommonProvider //将子集合的,多对一,对象设置为当前对象 foreach (var parentNav in parentNavs) foreach (var t1item in t1items) - _orm.SetEntityValueWithPropertyName(tbref.RefMiddleEntityType, nav, parentNav, t1item.Item1); + _orm.SetEntityValueWithPropertyName(tbref.RefEntityType, nav, parentNav, getListValue1(t1item.Item1, "")); //propertyName == "" 返回自身 } foreach (var t1items in dicList.Values) foreach (var t1item in t1items) @@ -992,9 +1000,14 @@ namespace FreeSql.Internal.CommonProvider } }; - _includeToList.Add(listObj => includeToListSyncOrAsync(listObj, false)); #if net40 + _includeToList.Add(listObj => includeToListSyncOrAsync(listObj, false)); #else + _includeToList.Add(listObj => + { + var task = includeToListSyncOrAsync(listObj, false); + if (task.Exception != null) throw task.Exception.InnerException ?? task.Exception; + }); _includeToListAsync.Add(listObj => includeToListSyncOrAsync(listObj, true)); #endif return this;