diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml index ab4c3bf2..045d21f7 100644 --- a/FreeSql.DbContext/FreeSql.DbContext.xml +++ b/FreeSql.DbContext/FreeSql.DbContext.xml @@ -130,13 +130,6 @@ 清空状态数据 - - - 根据 lambda 条件删除数据 - - - - 添加 @@ -534,3 +527,12 @@ +me="M:FreeSqlDbContextExtensions.CreateUnitOfWork(IFreeSql)"> + + 创建基于仓储功能的工作单元,务必使用 using 包含使用 + + + + + + diff --git a/FreeSql.Tests/FreeSql.Tests/UnitTest3.cs b/FreeSql.Tests/FreeSql.Tests/UnitTest3.cs index 172f4232..ff52cea6 100644 --- a/FreeSql.Tests/FreeSql.Tests/UnitTest3.cs +++ b/FreeSql.Tests/FreeSql.Tests/UnitTest3.cs @@ -187,9 +187,25 @@ namespace FreeSql.Tests public bool isxx { get; set; } } + public class tcate01 + { + [Column(IsIdentity = true)] + public int? Id { get; set; } + } + public class tshop01 + { + public Guid Id { get; set; } + + public int cateId { get; set; } + public tcate01 cate { get; set; } + } + [Fact] public void Test03() { + var tshop01sql = g.sqlite.Select().Include(a => a.cate).ToSql(); + + var testisnullsql1 = g.sqlite.Select().Where(a => SqlExt.IsNull(a.isxx, false).Equals( true)).ToSql(); var testisnullsql2 = g.sqlite.Select().Where(a => SqlExt.IsNull(a.isxx, false).Equals(false)).ToSql(); diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index fb99c6a7..3844b008 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -3006,6 +3006,154 @@ + + + 测试数据库是否连接正确,本方法执行如下命令: + MySql/SqlServer/PostgreSQL/达梦/人大金仓/神通: SELECT 1 + Oracle: SELECT 1 FROM dual + + 命令超时设置(秒) + true: 成功, false: 失败 + + + + 查询,若使用读写分离,查询【从库】条件cmdText.StartsWith("SELECT "),否则查询【主库】 + + + + + + + + + 查询,ExecuteReaderAsync(dr => {}, "select * from user where age > ?age", new { age = 25 }) + 提示:parms 参数还可以传 Dictionary<string, object> + + + + + + + 查询 + + + + + + + 查询,ExecuteArrayAsync("select * from user where age > ?age", new { age = 25 }) + 提示:parms 参数还可以传 Dictionary<string, object> + + + + + + + + 查询 + + + + + + + 查询,ExecuteDataSetAsync("select * from user where age > ?age; select 2", new { age = 25 }) + 提示:parms 参数还可以传 Dictionary<string, object> + + + + + + + + 查询 + + + + + + + 查询,ExecuteDataTableAsync("select * from user where age > ?age", new { age = 25 }) + 提示:parms 参数还可以传 Dictionary<string, object> + + + + + + + + 在【主库】执行 + + + + + + + + 在【主库】执行,ExecuteNonQueryAsync("delete from user where age > ?age", new { age = 25 }) + 提示:parms 参数还可以传 Dictionary<string, object> + + + + + + + + 在【主库】执行 + + + + + + + + 在【主库】执行,ExecuteScalarAsync("select 1 from user where age > ?age", new { age = 25 }) + 提示:parms 参数还可以传 Dictionary<string, object> + + + + + + + + 执行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 }) + 提示:parms 参数还可以传 Dictionary<string, object> + + + + + + + + + 执行SQL返回对象集合,Query<User>("select * from user where age > ?age; select * from address", new SqlParameter { ParameterName = "age", Value = 25 }) + + + + + + + + + + 执行SQL返回对象集合,Query<User, Address>("select * from user where age > ?age; select * from address", new { age = 25 }) + 提示:parms 参数还可以传 Dictionary<string, object> + + + + + + 可自定义解析表达式 @@ -3834,6 +3982,12 @@ 超时 + + + 获取资源 + + + 使用完毕后,归还资源 @@ -3904,6 +4058,12 @@ 资源对象 + + + 从对象池获取对象成功的时候触发,通过该方法统计或初始化对象 + + 资源对象 + 归还对象给对象池的时候触发 diff --git a/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderTransaction.cs b/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderTransaction.cs index 42966cc7..2ea6f90c 100644 --- a/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderTransaction.cs +++ b/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderTransaction.cs @@ -112,15 +112,16 @@ namespace FreeSql.Internal.CommonProvider void TransactionInternal(IsolationLevel? isolationLevel, Action handler) { + var requireTran = TransactionCurrentThread == null; try { - BeginTransaction(isolationLevel); + if (requireTran) BeginTransaction(isolationLevel); handler(); - CommitTransaction(); + if (requireTran) CommitTransaction(); } catch (Exception ex) { - RollbackTransaction(ex); + if (requireTran) RollbackTransaction(ex); throw ex; } }