Browse Source

Add Queryable. Select(exp,true)

pull/27/head
sunkaixuan 2 years ago
parent
commit
6bda78f3df
  1. 16
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs
  2. 15
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs
  3. 1
      Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

16
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs

@ -9,6 +9,7 @@ using System.Text.RegularExpressions;
using System.Reflection; using System.Reflection;
using System.Dynamic; using System.Dynamic;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.ObjectModel;
namespace SqlSugar namespace SqlSugar
{ {
@ -877,6 +878,21 @@ namespace SqlSugar
#endregion #endregion
#region Other #region Other
protected string AppendSelect<EntityType>(string sql, ReadOnlyCollection<ParameterExpression> parameters, List<EntityColumnInfo> columnsResult, int parameterIndex1)
{
var columns = this.Context.EntityMaintenance.GetEntityInfo<EntityType>().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) protected JoinQueryInfo GetJoinInfo(Expression joinExpression, JoinType joinType)
{ {
QueryBuilder.CheckExpressionNew(joinExpression, "Join"); QueryBuilder.CheckExpressionNew(joinExpression, "Join");

15
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider02-05.cs

@ -9,6 +9,7 @@ using System.Text.RegularExpressions;
using System.Reflection; using System.Reflection;
using System.Dynamic; using System.Dynamic;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.ObjectModel;
namespace SqlSugar namespace SqlSugar
{ {
@ -192,7 +193,19 @@ namespace SqlSugar
{ {
return _Select<TResult>(expression); return _Select<TResult>(expression);
} }
public ISugarQueryable<TResult> Select<TResult>(Expression<Func<T,T2, TResult>> expression, bool isAutoFill)
{
var sql = this.Clone().Select(expression).QueryBuilder.GetSelectValue;
if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*")
{
return this.Select<TResult>(expression);
}
var parameters = (expression as LambdaExpression).Parameters;
var columnsResult = this.Context.EntityMaintenance.GetEntityInfo<TResult>().Columns;
sql = AppendSelect<T>(sql, parameters, columnsResult, 0);
sql = AppendSelect<T2>(sql, parameters, columnsResult, 1);
return this.Select<TResult>(sql);
}
#endregion #endregion
#region Order #region Order

1
Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

@ -254,6 +254,7 @@ namespace SqlSugar
#region Select #region Select
ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, T2, TResult>> expression); ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, T2, TResult>> expression);
ISugarQueryable<TResult> Select<TResult>(Expression<Func<T,T2, TResult>> expression, bool isAutoFill);
#endregion #endregion
#region OrderBy #region OrderBy

Loading…
Cancel
Save