Skip to content

Commit 0de3931

Browse files
committed
- 优化 .Select<object>().WithSql(sql).ToList<T>() 体验;
1 parent ad83e0c commit 0de3931

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Examples/base_entity/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ static void Main(string[] args)
577577
#endregion
578578

579579
var objtsql1 = fsql.Select<object>().WithSql("select * from user1").ToList();
580+
var objtsql2 = fsql.Select<object>().WithSql("select * from user1").ToList<User1>();
580581

581582
var astsql = fsql.Select<AsTableLog, Sys_owner>()
582583
.InnerJoin((a, b) => a.id == b.Id)

FreeSql/Internal/CommonProvider/SelectProvider/Select1Provider.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,12 @@ MemberInitExpression GetIncludeManyNewInitExpression(IncludeManyNewInit imni)
371371
}
372372
return ret;
373373
}
374-
public List<TDto> ToList<TDto>() => typeof(T1) == typeof(TDto) ? ToList() as List<TDto> : ToList(GetToListDtoSelector<TDto>());
374+
public List<TDto> ToList<TDto>()
375+
{
376+
if (typeof(T1) == typeof(TDto)) return ToList() as List<TDto>;
377+
if (_tables.FirstOrDefault()?.Table.Type == typeof(object)) return ToList<TDto>("*");
378+
return ToList(GetToListDtoSelector<TDto>());
379+
}
375380
Expression<Func<T1, TDto>> GetToListDtoSelector<TDto>()
376381
{
377382
var expParam = _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a");

0 commit comments

Comments
 (0)