- 修复 实体类拥有构造参数时,ToList\<DTO\> 映射查询无效的 bug;

This commit is contained in:
2881099 2020-11-12 05:11:05 +08:00
parent dad05d83c9
commit 4ef38817ff
2 changed files with 6 additions and 3 deletions

View File

@ -15,6 +15,7 @@ namespace FreeSql.Tests
{
public ts_record parent { get; set; }
}
public record ts_record_dto(DateTime Date, int TemperatureC, string Summary);
[Fact]
public void LeftJoinNull01()
@ -24,6 +25,8 @@ namespace FreeSql.Tests
fsql.Delete<ts_record>().Where("1=1").ExecuteAffrows();
fsql.Insert(new ts_record(DateTime.Now, 1, 2, "123")).ExecuteAffrows();
var fores = fsql.Select<ts_record>().ToList();
var fores_dtos1 = fsql.Select<ts_record>().ToList<ts_record_dto>();
var fores_dtos2 = fsql.Select<ts_record>().ToList(a => new ts_record_dto(a.Date, a.TemperatureC, a.Summary));

View File

@ -273,9 +273,9 @@ namespace FreeSql.Internal
{
if (a.NodeType != ExpressionType.Constant) return true;
var constVal = (a as ConstantExpression)?.Value;
if (constVal == null) return true;
if (object.Equals(constVal, a.Type.CreateInstanceGetDefaultValue()) == false) return true;
return false;
if (constVal == null) return false; //- 修复 实体类拥有构造参数时ToList\<DTO\> 映射查询无效的 bug
if (object.Equals(constVal, a.Type.CreateInstanceGetDefaultValue())) return false;
return true;
})
))
{