diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs index 0326d5462..15bf73b6a 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs @@ -9,6 +9,7 @@ using System.Text.RegularExpressions; using System.Reflection; using System.Dynamic; using System.Threading.Tasks; +using System.Collections.ObjectModel; namespace SqlSugar { @@ -877,6 +878,21 @@ namespace SqlSugar #endregion #region Other + protected string AppendSelect(string sql, ReadOnlyCollection parameters, List columnsResult, int parameterIndex1) + { + var columns = this.Context.EntityMaintenance.GetEntityInfo().Columns; + var parameterName = parameters[parameterIndex1]; + foreach (var item in columns) + { + if (item.IsIgnore == false && columnsResult.Any(it => it.PropertyName == item.PropertyName) && !sql.Contains(SqlBuilder.GetTranslationColumnName(item.PropertyName))) + { + sql = $" {sql},{parameterName.Name}.{item.DbColumnName} AS {item.PropertyName} "; + } + } + + return sql; + } + protected JoinQueryInfo GetJoinInfo(Expression joinExpression, JoinType joinType) { QueryBuilder.CheckExpressionNew(joinExpression, "Join"); diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs index aa2b6ea7f..fb47d40ce 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs @@ -9,6 +9,7 @@ using System.Text.RegularExpressions; using System.Reflection; using System.Dynamic; using System.Threading.Tasks; +using System.Collections.ObjectModel; namespace SqlSugar { @@ -192,7 +193,19 @@ namespace SqlSugar { return _Select(expression); } - + public ISugarQueryable Select(Expression> expression, bool isAutoFill) + { + var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue; + if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") + { + return this.Select(expression); + } + var parameters = (expression as LambdaExpression).Parameters; + var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; + sql = AppendSelect(sql, parameters, columnsResult, 0); + sql = AppendSelect(sql, parameters, columnsResult, 1); + return this.Select(sql); + } #endregion #region Order diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs b/Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs index 25c87db67..71af9c70a 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs @@ -254,6 +254,7 @@ namespace SqlSugar #region Select ISugarQueryable Select(Expression> expression); + ISugarQueryable Select(Expression> expression, bool isAutoFill); #endregion #region OrderBy