mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 01:05:27 +08:00 
			
		
		
		
	- 修复 MapType 复杂表达式树解析 bug;#1062
This commit is contained in:
		@@ -16,6 +16,27 @@ namespace FreeSql.Tests
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    public class UnitTest5
 | 
					    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]
 | 
					        [Fact]
 | 
				
			||||||
        public void TestLambdaParameterWhereIn()
 | 
					        public void TestLambdaParameterWhereIn()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -526,7 +526,8 @@ namespace FreeSql.Internal.CommonProvider
 | 
				
			|||||||
                            var memberName = initExp.Bindings[a].Member.Name;
 | 
					                            var memberName = initExp.Bindings[a].Member.Name;
 | 
				
			||||||
                            if (_table.ColumnsByCsIgnore.ContainsKey(memberName)) continue;
 | 
					                            if (_table.ColumnsByCsIgnore.ContainsKey(memberName)) continue;
 | 
				
			||||||
                            if (_table.ColumnsByCs.TryGetValue(memberName, out var col) == false) throw new Exception($"找不到属性:{memberName}");
 | 
					                            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);
 | 
					                            _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;
 | 
					                            var memberName = newExp.Members[a].Name;
 | 
				
			||||||
                            if (_table.ColumnsByCsIgnore.ContainsKey(memberName)) continue;
 | 
					                            if (_table.ColumnsByCsIgnore.ContainsKey(memberName)) continue;
 | 
				
			||||||
                            if (_table.ColumnsByCs.TryGetValue(memberName, out var col) == false) throw new Exception($"找不到属性:{memberName}");
 | 
					                            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);
 | 
					                            _setIncr.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ").Append(memberValue);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user