diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs index 7a9109e5c..e45ed5dac 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs @@ -878,6 +878,20 @@ namespace SqlSugar #endregion #region Other + protected string AppendSelect(List entityColumnInfos,string sql, ReadOnlyCollection parameters, List columnsResult, int parameterIndex1) + { + var columns = entityColumnInfos; + var parameterName = parameters[parameterIndex1]; + foreach (var item in columns) + { + if (item.IsIgnore == false && columnsResult.Any(it => it.PropertyName.EqualCase(item.PropertyName)) && !sql.ToLower().Contains(SqlBuilder.GetTranslationColumnName(item.PropertyName.ToLower()))) + { + sql = $" {sql},{SqlBuilder.GetTranslationColumnName(item.DbColumnName)} AS {SqlBuilder.GetTranslationColumnName(item.PropertyName)} "; + } + } + + return sql; + } protected string AppendSelect(string sql, ReadOnlyCollection parameters, List columnsResult, int parameterIndex1) { var columns = this.Context.EntityMaintenance.GetEntityInfo().Columns; diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 833d5c932..c18783639 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -958,6 +958,23 @@ namespace SqlSugar Check.ExceptionEasy(this.QueryBuilder.Includes.HasValue(), $"use Includes(...).ToList(it=>new {typeof(TResult).Name} {{...}} )", $"Includes()后面禁使用Select,正确写法: ToList(it=>new {typeof(TResult).Name}{{....}})"); return _Select(expression); } + public ISugarQueryable Select(Expression> expression, bool isAutoFill) + { + var clone = this.Clone(); + //clone.QueryBuilder.LambdaExpressions.Index = QueryBuilder.LambdaExpressions.Index+1; + var ps = clone.Select(expression).QueryBuilder; + var sql = ps.GetSelectValue; + if (string.IsNullOrEmpty(sql) || sql.Trim() == "*") + { + return this.Select(expression); + } + this.QueryBuilder.Parameters = ps.Parameters; + this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; + var parameters = (expression as LambdaExpression).Parameters; + var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; + sql = AppendSelect(this.EntityInfo.Columns,sql, parameters, columnsResult, 0); + return this.Select(sql); + } public virtual ISugarQueryable Select() { diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs index 2caf02b4a..67ffb5cb2 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs @@ -195,11 +195,14 @@ namespace SqlSugar } public ISugarQueryable Select(Expression> expression, bool isAutoFill) { - var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue; + var clone = this.Clone().Select(expression); + var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { return this.Select(expression); } + this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; + this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); @@ -820,11 +823,14 @@ namespace SqlSugar #region Select public ISugarQueryable Select(Expression> expression, bool isAutoFill) { - var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue; + var clone = this.Clone().Select(expression); + var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { return this.Select(expression); } + this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; + this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); @@ -1336,11 +1342,14 @@ namespace SqlSugar #region Select public ISugarQueryable Select(Expression> expression, bool isAutoFill) { - var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue; + var clone = this.Clone().Select(expression); + var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { return this.Select(expression); } + this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; + this.QueryBuilder.LambdaExpressions.ParameterIndex=clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); @@ -1983,11 +1992,14 @@ namespace SqlSugar #region Select public ISugarQueryable Select(Expression> expression, bool isAutoFill) { - var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue; + var clone = this.Clone().Select(expression); + var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { return this.Select(expression); } + this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; + this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider06-10.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider06-10.cs index dd8a5a9bb..e81c2fb28 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider06-10.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider06-10.cs @@ -244,11 +244,14 @@ namespace SqlSugar } public ISugarQueryable Select(Expression> expression, bool isAutoFill) { - var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue; + var clone = this.Clone().Select(expression); + var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { return this.Select(expression); } + this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; + this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); @@ -868,11 +871,14 @@ namespace SqlSugar } public ISugarQueryable Select(Expression> expression, bool isAutoFill) { - var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue; + var clone = this.Clone().Select(expression); + var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { return this.Select(expression); } + this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; + this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); @@ -1460,11 +1466,14 @@ namespace SqlSugar } public ISugarQueryable Select(Expression> expression, bool isAutoFill) { - var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue; + var clone = this.Clone().Select(expression); + var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { return this.Select(expression); } + this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; + this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); @@ -1990,11 +1999,14 @@ namespace SqlSugar #region Select public ISugarQueryable Select(Expression> expression, bool isAutoFill) { - var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue; + var clone = this.Clone().Select(expression); + var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { return this.Select(expression); } + this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; + this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); @@ -2567,11 +2579,14 @@ namespace SqlSugar #region Select public ISugarQueryable Select(Expression> expression, bool isAutoFill) { - var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue; + var clone = this.Clone().Select(expression); + var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { return this.Select(expression); } + this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; + this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider11-12.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider11-12.cs index f77a6c5d1..f98c4dbaa 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider11-12.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider11-12.cs @@ -254,11 +254,14 @@ namespace SqlSugar #region Select public ISugarQueryable Select(Expression> expression, bool isAutoFill) { - var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue; + var clone = this.Clone().Select(expression); + var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { return this.Select(expression); } + this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; + this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); @@ -806,11 +809,14 @@ namespace SqlSugar #region Select public ISugarQueryable Select(Expression> expression, bool isAutoFill) { - var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue; + var clone = this.Clone().Select(expression); + var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { return this.Select(expression); } + this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; + this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); diff --git a/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs b/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs index f96fd90fd..171f0eab3 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs @@ -122,6 +122,7 @@ namespace SqlSugar Task AnyAsync(); ISugarQueryable Select(Expression> expression); + ISugarQueryable Select(Expression> expression,bool isAutoFill); ISugarQueryable Select(); ISugarQueryable Select(string select); ISugarQueryable Select(string select);