diff --git a/FreeSql.DbContext/FreeSql.DbContext.xml b/FreeSql.DbContext/FreeSql.DbContext.xml
index d9f91124..dc0203b8 100644
--- a/FreeSql.DbContext/FreeSql.DbContext.xml
+++ b/FreeSql.DbContext/FreeSql.DbContext.xml
@@ -110,13 +110,6 @@
清空状态数据
-
-
- 根据 lambda 条件删除数据
-
-
-
-
添加
diff --git a/FreeSql.Tests/FreeSql.Tests/UnitTest2.cs b/FreeSql.Tests/FreeSql.Tests/UnitTest2.cs
index 50e45747..feb4a6c3 100644
--- a/FreeSql.Tests/FreeSql.Tests/UnitTest2.cs
+++ b/FreeSql.Tests/FreeSql.Tests/UnitTest2.cs
@@ -252,6 +252,14 @@ namespace FreeSql.Tests
}
});
+ List<(Guid, DateTime)> contains2linqarr = new List<(Guid, DateTime)>();
+ Assert.Equal("SELECT 1 as1 FROM \"TestIgnoreDefaultValue\" a WHERE (1=0)", g.sqlite.Select().Where(a => contains2linqarr.ContainsMany(a.Id, a.ct1)).ToSql(a => 1).Replace("\r\n", ""));
+ g.sqlite.Select().Where(a => contains2linqarr.ContainsMany(a.Id, a.ct1)).ToList();
+
+ contains2linqarr.Add((Guid.NewGuid(), DateTime.Now));
+ contains2linqarr.Add((Guid.NewGuid(), DateTime.Now));
+ contains2linqarr.Add((Guid.NewGuid(), DateTime.Now));
+ g.sqlite.Select().Where(a => contains2linqarr.ContainsMany(a.Id, a.ct1)).ToList();
var start = DateTime.Now.Date;
var end = DateTime.Now.AddDays(1).Date.AddMilliseconds(-1);
diff --git a/FreeSql/DataAnnotations/ExpressionCallAttribute.cs b/FreeSql/DataAnnotations/ExpressionCallAttribute.cs
index c9c964e9..4342ff13 100644
--- a/FreeSql/DataAnnotations/ExpressionCallAttribute.cs
+++ b/FreeSql/DataAnnotations/ExpressionCallAttribute.cs
@@ -13,6 +13,13 @@ namespace FreeSql.DataAnnotations
public class ExpressionCallAttribute : Attribute
{
}
+ ///
+ /// 自定义表达式函数解析的时候,指定参数不解析 SQL,而是直接传进来
+ ///
+ [AttributeUsage(AttributeTargets.Parameter)]
+ public class RawValueAttribute : Attribute
+ {
+ }
public class ExpressionCallContext
{
@@ -37,6 +44,11 @@ namespace FreeSql.DataAnnotations
///
public List UserParameters { get; internal set; }
+ ///
+ /// 将 c# 对象转换为 SQL
+ ///
+ public Func
+
+
+ 自定义表达式函数解析的时候,指定参数不解析 SQL,而是直接传进来
+
+
数据库类型,可用于适配多种数据库环境
@@ -225,6 +230,11 @@
注意:本属性只有 Where 的表达式解析才可用
+
+
+ 将 c# 对象转换为 SQL
+
+
返回表达式函数表示的 SQL 字符串
@@ -2784,6 +2794,40 @@
+
+
+ C#:从元组集合中查找 exp1, exp2 是否存在
+ SQL:
+ exp1 = that[0].Item1 and exp2 = that[0].Item2 OR
+ exp1 = that[1].Item1 and exp2 = that[1].Item2 OR
+ ...
+ 注意:当 that 为 null 或 empty 时,返回 1=0
+
+
+
+
+
+
+
+
+
+
+ C#:从元组集合中查找 exp1, exp2 是否存在
+ SQL:
+ exp1 = that[0].Item1 and exp2 = that[0].Item2 and exp3 = that[0].Item3 OR
+ exp1 = that[1].Item1 and exp2 = that[1].Item2 and exp3 = that[1].Item3 OR
+ ...
+ 注意:当 that 为 null 或 empty 时,返回 1=0
+
+
+
+
+
+
+
+
+
+
使用 and 拼接两个 lambda 表达式
diff --git a/FreeSql/Internal/CommonExpression.cs b/FreeSql/Internal/CommonExpression.cs
index 23156372..b8fdfa9c 100644
--- a/FreeSql/Internal/CommonExpression.cs
+++ b/FreeSql/Internal/CommonExpression.cs
@@ -553,15 +553,15 @@ namespace FreeSql.Internal
exp3.Method.GetCustomAttributes(typeof(ExpressionCallAttribute), true).Any()
))
{
- var ecc = new ExpressionCallContext { DataType = _ado.DataType, UserParameters = tsc.dbParams == null ? null : new List() };
+ var ecc = new ExpressionCallContext { DataType = _ado.DataType, UserParameters = tsc.dbParams == null ? null : new List(), FormatSql = obj => formatSql(obj, null, null, null) };
var exp3MethodParams = exp3.Method.GetParameters();
var dbParamsIndex = tsc.dbParams?.Count;
- ecc.ParsedContent.Add(exp3MethodParams[0].Name, ExpressionLambdaToSql(exp3.Arguments[0], tsc));
+ ecc.ParsedContent.Add(exp3MethodParams[0].Name, exp3MethodParams[0].GetCustomAttributes(typeof(RawValueAttribute), true).Any() ? null: ExpressionLambdaToSql(exp3.Arguments[0], tsc));
if (tsc.dbParams?.Count > dbParamsIndex) ecc.DbParameter = tsc.dbParams.Last();
List oldDbParams = tsc.SetDbParamsReturnOld(null);
for (var a = 1; a < exp3.Arguments.Count; a++)
if (exp3.Arguments[a].Type != typeof(ExpressionCallContext))
- ecc.ParsedContent.Add(exp3MethodParams[a].Name, ExpressionLambdaToSql(exp3.Arguments[a], tsc));
+ ecc.ParsedContent.Add(exp3MethodParams[a].Name, exp3MethodParams[a].GetCustomAttributes(typeof(RawValueAttribute), true).Any() ? null : ExpressionLambdaToSql(exp3.Arguments[a], tsc));
tsc.SetDbParamsReturnOld(oldDbParams);
var exp3InvokeParams = new object[exp3.Arguments.Count];
@@ -570,10 +570,13 @@ namespace FreeSql.Internal
if (exp3.Arguments[a].Type != typeof(ExpressionCallContext))
{
var eccContent = ecc.ParsedContent[exp3MethodParams[a].Name];
- exp3InvokeParams[a] = Utils.GetDataReaderValue(exp3.Arguments[a].Type,
- eccContent.StartsWith("N'") ?
- eccContent.Substring(1).Trim('\'').Replace("''", "'") :
- eccContent.Trim('\'').Replace("''", "'"));// exp3.Arguments[a].Type.CreateInstanceGetDefaultValue();
+ if (eccContent == null)
+ exp3InvokeParams[a] = Expression.Lambda(exp3.Arguments[a]).Compile().DynamicInvoke();
+ else
+ exp3InvokeParams[a] = Utils.GetDataReaderValue(exp3.Arguments[a].Type,
+ eccContent.StartsWith("N'") ?
+ eccContent.Substring(1).Trim('\'').Replace("''", "'") :
+ eccContent.Trim('\'').Replace("''", "'"));// exp3.Arguments[a].Type.CreateInstanceGetDefaultValue();
}
else
exp3InvokeParams[a] = ecc;