Skip to content

Commit 7317047

Browse files
authored
Merge pull request #2244 from 2881099/master
- 增强 ToList new T 也支持 dto 自动映射的细节规则(若未指定过);#2241
2 parents e9879e4 + 5863a44 commit 7317047

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

FreeSql/Internal/CommonExpression.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,20 @@ void LocalSetFieldAlias(ref int localIndex, bool isdiymemexp)
368368
ReadAnonymousField(_tables, _tableRule, field, child, ref index, initExpArg, select, diymemexp, whereGlobalFilter, findIncludeMany, findSubSelectMany, false);
369369
}
370370
}
371-
else if (isAllDtoMap && _tables != null && _tables.Any() && initExp.NewExpression.Type != _tables.FirstOrDefault().Table.Type)
371+
else if (isAllDtoMap && _tables != null && _tables.Any() &&
372+
(
373+
initExp.NewExpression.Type != _tables[0].Table.Type ||
374+
initExp.Bindings.Any(a =>
375+
// #2241 如果 new Dto 和 T 相同,并且未使用过例如:Name = t.Name,则也认为是 Dto 自动赋加所有属性来查询
376+
{
377+
var aExp = a as MemberAssignment;
378+
if (aExp == null) return true;
379+
if (aExp.Expression is MemberExpression aExpRight == false) return true;
380+
if (aExpRight.Expression == _tables[0].Parameter &&
381+
aExpRight.Member.Name == a.Member.Name) return false;
382+
return true;
383+
})
384+
))
372385
{
373386
var dicBindings = initExp.Bindings?.Select(a => a.Member.Name).Distinct().ToDictionary(a => a, a => false);
374387
//dto 映射

0 commit comments

Comments
 (0)