Update linq dynamic core

This commit is contained in:
sunkaixuan 2024-04-08 10:10:43 +08:00
parent 72c04ea4e4
commit 362638e4d8
3 changed files with 30 additions and 1 deletions

View File

@ -199,10 +199,19 @@ namespace SqlSugar
{
throw new NotSupportedException("Can only be used in expressions");
}
public static bool GreaterThan_LinqDynamicCore(object thisValue, object ltValue)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static bool LessThan(object thisValue, object ltValue)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static bool LessThan_LinqDynamicCore(object thisValue, object ltValue)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static bool LessThanOrEqual(object thisValue, object ltValue)
{
throw new NotSupportedException("Can only be used in expressions");

View File

@ -970,6 +970,10 @@ namespace SqlSugar
return this.Context.DbMehtods.Like(model);
case "ToSingle":
return this.Context.DbMehtods.ToSingle(model);
case "GreaterThan_LinqDynamicCore":
return this.Context.DbMehtods.GreaterThan(model);
case "LessThan_LinqDynamicCore":
return this.Context.DbMehtods.LessThan(model);
default:
if (typeof(IDbMethods).GetMethods().Any(it => it.Name == name))
{

View File

@ -1,5 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
@ -22,6 +22,8 @@ namespace SqlSugar
var sql = ReplaceFormatParameters(whereSql.Format);
sql = CompatibleDynamicLinqCoreBug(sql);
// 构建动态表达式,使用常量表达式和 whereSql 中的参数值
var lambda = SqlSugarDynamicExpressionParser.ParseLambda(
@ -33,6 +35,20 @@ namespace SqlSugar
return lambda;
}
private static string CompatibleDynamicLinqCoreBug(string sql)
{
//Compatible DynamicCore.Linq bug
if (sql?.Contains("SqlFunc.") == true)
{
sql = sql.Replace("SqlFunc.LessThan(", "SqlFunc.LessThan_LinqDynamicCore(");
sql = sql.Replace("SqlFunc.LessThan (", "SqlFunc.LessThan_LinqDynamicCore (");
sql = sql.Replace("SqlFunc.GreaterThan(", "SqlFunc.GreaterThan_LinqDynamicCore(");
sql = sql.Replace("SqlFunc.GreaterThan (", "SqlFunc.GreaterThan_LinqDynamicCore (");
}
return sql;
}
public static LambdaExpression GetObject(Type entityType, string shortName, FormattableString whereSql)
{
var parameter = Expression.Parameter(entityType, shortName);