mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 修复 MapType 复杂表达式树解析 bug;#1062
This commit is contained in:
parent
69c74590f4
commit
198e027c48
@ -16,6 +16,27 @@ namespace FreeSql.Tests
|
||||
{
|
||||
public class UnitTest5
|
||||
{
|
||||
// DTO
|
||||
public class TestDto
|
||||
{
|
||||
public decimal ratio { get; set; }
|
||||
public bool is_lock { get; set; }
|
||||
}
|
||||
[Fact]
|
||||
public void TestDoubleWhereBug()
|
||||
{
|
||||
var fsql = g.mysql;
|
||||
// 测试例子
|
||||
var test = new TestDto();
|
||||
test.ratio = 2.1M;
|
||||
var sql = fsql.Update<TestDto>().Set(m => new TestDto
|
||||
{
|
||||
is_lock = test.ratio < 1 //这里生成的SQL语句有问题 ratio = 0.9 或 1.9 或 2.1 等等都是生成的是1
|
||||
}).Where(m => test.ratio < 1).ToSql();
|
||||
Assert.Equal(@"UPDATE TestDto SET is_lock = 2.1 < 1
|
||||
WHERE (2.1 < 1)", sql);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestLambdaParameterWhereIn()
|
||||
{
|
||||
|
@ -526,7 +526,8 @@ namespace FreeSql.Internal.CommonProvider
|
||||
var memberName = initExp.Bindings[a].Member.Name;
|
||||
if (_table.ColumnsByCsIgnore.ContainsKey(memberName)) continue;
|
||||
if (_table.ColumnsByCs.TryGetValue(memberName, out var col) == false) throw new Exception($"找不到属性:{memberName}");
|
||||
var memberValue = _commonExpression.ExpressionLambdaToSql(initAssignExp.Expression, new CommonExpression.ExpTSC { isQuoteName = true, mapType = col.Attribute.MapType });
|
||||
var memberValue = _commonExpression.ExpressionLambdaToSql(initAssignExp.Expression, new CommonExpression.ExpTSC { isQuoteName = true,
|
||||
mapType = initAssignExp.Expression is BinaryExpression ? null : col.Attribute.MapType });
|
||||
_setIncr.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ").Append(memberValue);
|
||||
}
|
||||
}
|
||||
@ -540,7 +541,8 @@ namespace FreeSql.Internal.CommonProvider
|
||||
var memberName = newExp.Members[a].Name;
|
||||
if (_table.ColumnsByCsIgnore.ContainsKey(memberName)) continue;
|
||||
if (_table.ColumnsByCs.TryGetValue(memberName, out var col) == false) throw new Exception($"找不到属性:{memberName}");
|
||||
var memberValue = _commonExpression.ExpressionLambdaToSql(newExp.Arguments[a], new CommonExpression.ExpTSC { isQuoteName = true, mapType = col.Attribute.MapType });
|
||||
var memberValue = _commonExpression.ExpressionLambdaToSql(newExp.Arguments[a], new CommonExpression.ExpTSC { isQuoteName = true,
|
||||
mapType = newExp.Arguments[a] is BinaryExpression ? null : col.Attribute.MapType });
|
||||
_setIncr.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ").Append(memberValue);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user