You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECT .. FROM ..
WHERE (a."Id", a."ct1") in (
('685ee1f6-bdf6-4719-a291-c709b8a1378f','2019-12-07 23:55:27'),
('5ecd838a-06a0-4c81-be43-1e77633b7404', '2019-12-07 23:55:27'))
非 ORACLE 产生如下 SQL:
SELECT .. FROM ..
WHERE (a."Id"='685ee1f6-bdf6-4719-a291-c709b8a1378f'AND a."ct1"='2019-12-07 23:55:27'OR
a."Id"='5ecd838a-06a0-4c81-be43-1e77633b7404'AND a."ct1"='2019-12-07 23:55:27')
代码实现:
usingFreeSql.DataAnnotations;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading;[ExpressionCall]publicstaticclassMyFreeSqlExpressionCall{publicstaticThreadLocal<ExpressionCallContext>expContext=newThreadLocal<ExpressionCallContext>();/// <summary>/// C#:从元组集合中查找 exp1, exp2 是否存在<para></para>/// SQL: <para></para>/// exp1 = that[0].Item1 and exp2 = that[0].Item2 OR <para></para>/// exp1 = that[1].Item1 and exp2 = that[1].Item2 OR <para></para>/// ... <para></para>/// 注意:当 that 为 null 或 empty 时,返回 1=0 <para></para>/// Oracle: (Id, Name) IN ((1, "name1"), (2, "name2"))/// </summary>/// <typeparam name="T1"></typeparam>/// <typeparam name="T2"></typeparam>/// <param name="that"></param>/// <param name="exp1"></param>/// <param name="exp2"></param>/// <returns></returns>publicstaticboolContains<T1,T2>([RawValue]thisIEnumerable<(T1,T2)>that,T1exp1,T2exp2){if(expContext.IsValueCreated==false||expContext.Value==null||expContext.Value.ParsedContent==null)returnthat?.Any(a =>a.Item1.Equals(exp1)&&a.Item2.Equals(exp2))==true;if(that?.Any()!=true){expContext.Value.Result="1=0";returnfalse;}varsb=newStringBuilder();varidx=0;switch(expContext.Value.DataType){caseFreeSql.DataType.Oracle:caseFreeSql.DataType.OdbcOracle:sb.Append("(").Append(expContext.Value.ParsedContent["exp1"]).Append(", ").Append(expContext.Value.ParsedContent["exp2"]).Append(") IN (");foreach(variteminthat){if(idx++>0)sb.Append(", ");sb.Append("(").Append(expContext.Value.FormatSql(FreeSql.Internal.Utils.GetDataReaderValue(typeof(T1),item.Item1))).Append(", ").Append(expContext.Value.FormatSql(FreeSql.Internal.Utils.GetDataReaderValue(typeof(T2),item.Item2))).Append(")");}sb.Append(")");expContext.Value.Result=sb.ToString();returnfalse;}foreach(variteminthat){if(idx++>0)sb.Append(" OR \r\n");sb.Append(expContext.Value.ParsedContent["exp1"]).Append(" = ").Append(expContext.Value.FormatSql(FreeSql.Internal.Utils.GetDataReaderValue(typeof(T1),item.Item1))).Append(" AND ").Append(expContext.Value.ParsedContent["exp2"]).Append(" = ").Append(expContext.Value.FormatSql(FreeSql.Internal.Utils.GetDataReaderValue(typeof(T2),item.Item2)));}expContext.Value.Result=sb.ToString();returntrue;}}
The text was updated successfully, but these errors were encountered:
FreeSql 基础库为了不依赖 System.ValueType.dll,所以将以下代码抽离了出来。
Oracle 产生如下SQL:
非 ORACLE 产生如下 SQL:
代码实现:
The text was updated successfully, but these errors were encountered: