From 54564b5d83cf44787a0d963e43352487df6aaf33 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Tue, 2 Feb 2021 23:07:53 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=20=E8=A1=A8=E8=BE=BE?= =?UTF-8?q?=E5=BC=8F=E6=A0=91=E8=A7=A3=E6=9E=90=20MapType=20=E6=8A=8A?= =?UTF-8?q?=E5=B0=8F=E6=95=B0=E4=BD=8D=E8=BD=AC=E6=8D=A2=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E7=9A=84=20bug=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FreeSql.Tests/FreeSql.Tests/UnitTest5.cs | 43 ++++++ FreeSql/FreeSql.xml | 183 +++++++++++++++++++++++ FreeSql/Internal/CommonExpression.cs | 5 +- 3 files changed, 229 insertions(+), 2 deletions(-) diff --git a/FreeSql.Tests/FreeSql.Tests/UnitTest5.cs b/FreeSql.Tests/FreeSql.Tests/UnitTest5.cs index a8c3b9df..484420de 100644 --- a/FreeSql.Tests/FreeSql.Tests/UnitTest5.cs +++ b/FreeSql.Tests/FreeSql.Tests/UnitTest5.cs @@ -14,6 +14,49 @@ namespace FreeSql.Tests { public class UnitTest5 { + [Fact] + public void DebugUpdateSet01() + { + var fsql = g.mysql; + + var report = new + { + NotTaxCostPrice = 47.844297M, + ProductId = Guid.Empty, + MerchantId = Guid.Empty, + }; + var sql = fsql.Update() + .NoneParameter() + .Set(a => a.NotTaxTotalCostPrice == report.NotTaxCostPrice * a.CurrentQty) + .Set(a => a.NotTaxCostPrice, report.NotTaxCostPrice) + .Where(x => x.ProductId == report.ProductId && x.MerchantId == report.MerchantId) + .ToSql(); + Assert.Equal(@"UPDATE `ProductStockBak` SET `NotTaxTotalCostPrice` = 47.844297 * `CurrentQty`, `NotTaxCostPrice` = 47.844297 +WHERE (`ProductId` = '00000000-0000-0000-0000-000000000000' AND `MerchantId` = '00000000-0000-0000-0000-000000000000')", sql); + } + public partial class ProductStockBak + { + [Column(IsPrimary = true)] + public Guid ProductStockBakId { get; set; } + + public DateTime BakTime { get; set; } + public Guid GoodsId { get; set; } + public Guid ProductId { get; set; } + public Guid MerchantId { get; set; } + public string ProductCode { get; set; } + public string Barcode { get; set; } + public long CurrentQty { get; set; } + public long UsableQty { get; set; } + public long OrderQty { get; set; } + public long LockQty { get; set; } + public decimal CostPrice { get; set; } + public decimal TotalCostPrice { get; set; } + public decimal NotTaxCostPrice { get; set; } + public decimal NotTaxTotalCostPrice { get; set; } + public DateTime? CreationTime { get; set; } + public DateTime? LastModificationTime { get; set; } + } + [Fact] public void TestDistinctCount() { diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml index 36476114..0f9eda96 100644 --- a/FreeSql/FreeSql.xml +++ b/FreeSql/FreeSql.xml @@ -3141,6 +3141,177 @@ + + + 测试数据库是否连接正确,本方法执行如下命令: + 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> + + + + + + + + 可自定义解析表达式 @@ -3974,6 +4145,12 @@ 超时 + + + 获取资源 + + + 使用完毕后,归还资源 @@ -4044,6 +4221,12 @@ 资源对象 + + + 从对象池获取对象成功的时候触发,通过该方法统计或初始化对象 + + 资源对象 + 归还对象给对象池的时候触发 diff --git a/FreeSql/Internal/CommonExpression.cs b/FreeSql/Internal/CommonExpression.cs index ae1ffa9c..c5da12e1 100644 --- a/FreeSql/Internal/CommonExpression.cs +++ b/FreeSql/Internal/CommonExpression.cs @@ -616,7 +616,7 @@ namespace FreeSql.Internal Type oldMapType = null; var left = ExpressionLambdaToSql(leftExp, tsc); var leftMapColumn = SearchColumnByField(tsc._tables, tsc.currentTable, left); - var isLeftMapType = leftMapColumn != null && new[] { "AND", "OR" }.Contains(oper) == false && (leftMapColumn.Attribute.MapType != rightExp.Type || leftMapColumn.CsType != rightExp.Type); + var isLeftMapType = leftMapColumn != null && new[] { "AND", "OR", "*", "/", "+", "-" }.Contains(oper) == false && (leftMapColumn.Attribute.MapType != rightExp.Type || leftMapColumn.CsType != rightExp.Type); ColumnInfo rightMapColumn = null; var isRightMapType = false; if (isLeftMapType) oldMapType = tsc.SetMapTypeReturnOld(leftMapColumn.Attribute.MapType); @@ -635,7 +635,8 @@ namespace FreeSql.Internal if (leftMapColumn == null) { rightMapColumn = SearchColumnByField(tsc._tables, tsc.currentTable, right); - isRightMapType = rightMapColumn != null && new[] { "AND", "OR" }.Contains(oper) == false && (rightMapColumn.Attribute.MapType != leftExp.Type || rightMapColumn.CsType != leftExp.Type); + //.Set(a => a.NotTaxTotalCostPrice == report.NotTaxCostPrice * a.CurrentQty) * / + - 解决 report.NotTaxCostPrice 小数点问题 + isRightMapType = rightMapColumn != null && new[] { "AND", "OR", "*", "/", "+", "-" }.Contains(oper) == false && (rightMapColumn.Attribute.MapType != leftExp.Type || rightMapColumn.CsType != leftExp.Type); if (isRightMapType) { oldMapType = tsc.SetMapTypeReturnOld(rightMapColumn.Attribute.MapType);