mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 01:58:13 +08:00
Queryable.Select (dynamic exp)
This commit is contained in:
@@ -8,7 +8,7 @@ using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Reflection;
|
||||
using System.Dynamic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
@@ -1339,6 +1339,15 @@ namespace SqlSugar
|
||||
}
|
||||
return _Select<TResult>(expression);
|
||||
}
|
||||
public ISugarQueryable<TResult> Select<TResult>(string expShortName, FormattableString expSelect, Type propertyType)
|
||||
{
|
||||
var exp = DynamicCoreHelper.GetMember(typeof(TResult),propertyType, expShortName, expSelect);
|
||||
return _Select<TResult>(exp);
|
||||
}
|
||||
public ISugarQueryable<T> Select(string expShortName, FormattableString expSelect,Type propertyType)
|
||||
{
|
||||
return Select<T>(expShortName, expSelect, propertyType);
|
||||
}
|
||||
public virtual ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
if (IsAppendNavColumns())
|
||||
|
@@ -151,6 +151,8 @@ namespace SqlSugar
|
||||
Task<bool> AnyAsync(Expression<Func<T, bool>> expression, CancellationToken token);
|
||||
bool Any();
|
||||
Task<bool> AnyAsync();
|
||||
ISugarQueryable<TResult> Select<TResult>(string expShortName, FormattableString expSelect, Type propertyType);
|
||||
ISugarQueryable<T> Select(string expShortName, FormattableString expSelect, Type propertyType);
|
||||
ISugarQueryable<TResult> Select<TResult>(Expression expression);
|
||||
ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression);
|
||||
ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression,bool isAutoFill);
|
||||
|
@@ -32,6 +32,26 @@ namespace SqlSugar
|
||||
|
||||
return lambda;
|
||||
}
|
||||
public static LambdaExpression GetMember(Type entityType,Type propertyType, string shortName, FormattableString memberSql)
|
||||
{
|
||||
var parameter = Expression.Parameter(entityType, "it");
|
||||
|
||||
// 提取 FormattableString 中的参数值
|
||||
var arguments = memberSql.GetArguments();
|
||||
|
||||
|
||||
var sql = ReplaceFormatParameters(memberSql.Format);
|
||||
|
||||
// 构建动态表达式,使用常量表达式和 whereSql 中的参数值
|
||||
var lambda = SqlSugarDynamicExpressionParser.ParseLambda(
|
||||
new[] { parameter },
|
||||
propertyType,
|
||||
sql,
|
||||
memberSql.GetArguments()
|
||||
);
|
||||
|
||||
return lambda;
|
||||
}
|
||||
private static string ReplaceFormatParameters(string format)
|
||||
{
|
||||
int parameterIndex = 0; // 起始参数索引
|
||||
|
Reference in New Issue
Block a user