mirror of
				https://github.com/nsnail/FreeSql.git
				synced 2025-11-04 17:20:49 +08:00 
			
		
		
		
	repair bug: ILIst.Contains Expression #16
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
using FreeSql.Internal;
 | 
			
		||||
using FreeSql.Internal.Model;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Linq.Expressions;
 | 
			
		||||
@@ -21,7 +22,7 @@ namespace FreeSql.MySql {
 | 
			
		||||
					if (objType?.FullName == "System.Byte[]") return null;
 | 
			
		||||
 | 
			
		||||
					var argIndex = 0;
 | 
			
		||||
					if (objType == null && callExp.Method.DeclaringType.FullName == typeof(Enumerable).FullName) {
 | 
			
		||||
					if (objType == null && callExp.Method.DeclaringType == typeof(Enumerable)) {
 | 
			
		||||
						objExp = callExp.Arguments.FirstOrDefault();
 | 
			
		||||
						objType = objExp?.Type;
 | 
			
		||||
						argIndex++;
 | 
			
		||||
@@ -29,7 +30,7 @@ namespace FreeSql.MySql {
 | 
			
		||||
					if (objType == null) objType = callExp.Method.DeclaringType;
 | 
			
		||||
					if (objType != null) {
 | 
			
		||||
						var left = objExp == null ? null : getExp(objExp);
 | 
			
		||||
						if (objType.IsArray == true) {
 | 
			
		||||
						if (objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
 | 
			
		||||
							switch (callExp.Method.Name) {
 | 
			
		||||
								case "Contains":
 | 
			
		||||
									//判断 in
 | 
			
		||||
@@ -46,7 +47,27 @@ namespace FreeSql.MySql {
 | 
			
		||||
						if (a > 0) arrSb.Append(",");
 | 
			
		||||
						arrSb.Append(getExp(arrExp.Expressions[a]));
 | 
			
		||||
					}
 | 
			
		||||
					if (arrSb.Length == 1) arrSb.Append("NULL");
 | 
			
		||||
					return arrSb.Append(")").ToString();
 | 
			
		||||
				case ExpressionType.ListInit:
 | 
			
		||||
					var listExp = exp as ListInitExpression;
 | 
			
		||||
					var listSb = new StringBuilder();
 | 
			
		||||
					listSb.Append("(");
 | 
			
		||||
					for (var a = 0; a < listExp.Initializers.Count; a++) {
 | 
			
		||||
						if (listExp.Initializers[a].Arguments.Any() == false) continue;
 | 
			
		||||
						if (a > 0) listSb.Append(",");
 | 
			
		||||
						listSb.Append(getExp(listExp.Initializers[a].Arguments.FirstOrDefault()));
 | 
			
		||||
					}
 | 
			
		||||
					if (listSb.Length == 1) listSb.Append("NULL");
 | 
			
		||||
					return listSb.Append(")").ToString();
 | 
			
		||||
				case ExpressionType.New:
 | 
			
		||||
					var newExp = exp as NewExpression;
 | 
			
		||||
					if (typeof(IList).IsAssignableFrom(newExp.Type)) {
 | 
			
		||||
						if (newExp.Arguments.Count == 0) return "(NULL)";
 | 
			
		||||
						if (typeof(IEnumerable).IsAssignableFrom(newExp.Arguments[0].Type) == false) return "(NULL)";
 | 
			
		||||
						return getExp(newExp.Arguments[0]);
 | 
			
		||||
					}
 | 
			
		||||
					return null;
 | 
			
		||||
			}
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
using FreeSql.Internal;
 | 
			
		||||
using FreeSql.Internal.Model;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Linq.Expressions;
 | 
			
		||||
@@ -21,7 +22,7 @@ namespace FreeSql.Oracle {
 | 
			
		||||
					if (objType?.FullName == "System.Byte[]") return null;
 | 
			
		||||
 | 
			
		||||
					var argIndex = 0;
 | 
			
		||||
					if (objType == null && callExp.Method.DeclaringType.FullName == typeof(Enumerable).FullName) {
 | 
			
		||||
					if (objType == null && callExp.Method.DeclaringType == typeof(Enumerable)) {
 | 
			
		||||
						objExp = callExp.Arguments.FirstOrDefault();
 | 
			
		||||
						objType = objExp?.Type;
 | 
			
		||||
						argIndex++;
 | 
			
		||||
@@ -29,7 +30,7 @@ namespace FreeSql.Oracle {
 | 
			
		||||
					if (objType == null) objType = callExp.Method.DeclaringType;
 | 
			
		||||
					if (objType != null) {
 | 
			
		||||
						var left = objExp == null ? null : getExp(objExp);
 | 
			
		||||
						if (objType.IsArray == true) {
 | 
			
		||||
						if (objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
 | 
			
		||||
							switch (callExp.Method.Name) {
 | 
			
		||||
								case "Contains":
 | 
			
		||||
									//判断 in
 | 
			
		||||
@@ -46,7 +47,27 @@ namespace FreeSql.Oracle {
 | 
			
		||||
						if (a > 0) arrSb.Append(",");
 | 
			
		||||
						arrSb.Append(getExp(arrExp.Expressions[a]));
 | 
			
		||||
					}
 | 
			
		||||
					if (arrSb.Length == 1) arrSb.Append("NULL");
 | 
			
		||||
					return arrSb.Append(")").ToString();
 | 
			
		||||
				case ExpressionType.ListInit:
 | 
			
		||||
					var listExp = exp as ListInitExpression;
 | 
			
		||||
					var listSb = new StringBuilder();
 | 
			
		||||
					listSb.Append("(");
 | 
			
		||||
					for (var a = 0; a < listExp.Initializers.Count; a++) {
 | 
			
		||||
						if (listExp.Initializers[a].Arguments.Any() == false) continue;
 | 
			
		||||
						if (a > 0) listSb.Append(",");
 | 
			
		||||
						listSb.Append(getExp(listExp.Initializers[a].Arguments.FirstOrDefault()));
 | 
			
		||||
					}
 | 
			
		||||
					if (listSb.Length == 1) listSb.Append("NULL");
 | 
			
		||||
					return listSb.Append(")").ToString();
 | 
			
		||||
				case ExpressionType.New:
 | 
			
		||||
					var newExp = exp as NewExpression;
 | 
			
		||||
					if (typeof(IList).IsAssignableFrom(newExp.Type)) {
 | 
			
		||||
						if (newExp.Arguments.Count == 0) return "(NULL)";
 | 
			
		||||
						if (typeof(IEnumerable).IsAssignableFrom(newExp.Arguments[0].Type) == false) return "(NULL)";
 | 
			
		||||
						return getExp(newExp.Arguments[0]);
 | 
			
		||||
					}
 | 
			
		||||
					return null;
 | 
			
		||||
			}
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
using FreeSql.Internal.Model;
 | 
			
		||||
using Newtonsoft.Json.Linq;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Linq.Expressions;
 | 
			
		||||
@@ -26,7 +27,7 @@ namespace FreeSql.PostgreSQL {
 | 
			
		||||
					if (objType?.FullName == "System.Byte[]") return null;
 | 
			
		||||
 | 
			
		||||
					var argIndex = 0;
 | 
			
		||||
					if (objType == null && callExp.Method.DeclaringType.FullName == typeof(Enumerable).FullName) {
 | 
			
		||||
					if (objType == null && callExp.Method.DeclaringType == typeof(Enumerable)) {
 | 
			
		||||
						objExp = callExp.Arguments.FirstOrDefault();
 | 
			
		||||
						objType = objExp?.Type;
 | 
			
		||||
						argIndex++;
 | 
			
		||||
@@ -34,7 +35,7 @@ namespace FreeSql.PostgreSQL {
 | 
			
		||||
					if (objType == null) objType = callExp.Method.DeclaringType;
 | 
			
		||||
					if (objType != null) {
 | 
			
		||||
						var left = objExp == null ? null : getExp(objExp);
 | 
			
		||||
						if (objType.IsArray == true) {
 | 
			
		||||
						if (objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
 | 
			
		||||
							switch (callExp.Method.Name) {
 | 
			
		||||
								case "Any":
 | 
			
		||||
									if (left.StartsWith("(") || left.EndsWith(")")) left = $"array[{left.TrimStart('(').TrimEnd(')')}]";
 | 
			
		||||
@@ -141,7 +142,27 @@ namespace FreeSql.PostgreSQL {
 | 
			
		||||
						if (a > 0) arrSb.Append(",");
 | 
			
		||||
						arrSb.Append(getExp(arrExp.Expressions[a]));
 | 
			
		||||
					}
 | 
			
		||||
					if (arrSb.Length == 1) arrSb.Append("NULL");
 | 
			
		||||
					return arrSb.Append("]").ToString();
 | 
			
		||||
				case ExpressionType.ListInit:
 | 
			
		||||
					var listExp = exp as ListInitExpression;
 | 
			
		||||
					var listSb = new StringBuilder();
 | 
			
		||||
					listSb.Append("(");
 | 
			
		||||
					for (var a = 0; a < listExp.Initializers.Count; a++) {
 | 
			
		||||
						if (listExp.Initializers[a].Arguments.Any() == false) continue;
 | 
			
		||||
						if (a > 0) listSb.Append(",");
 | 
			
		||||
						listSb.Append(getExp(listExp.Initializers[a].Arguments.FirstOrDefault()));
 | 
			
		||||
					}
 | 
			
		||||
					if (listSb.Length == 1) listSb.Append("NULL");
 | 
			
		||||
					return listSb.Append(")").ToString();
 | 
			
		||||
				case ExpressionType.New:
 | 
			
		||||
					var newExp = exp as NewExpression;
 | 
			
		||||
					if (typeof(IList).IsAssignableFrom(newExp.Type)) {
 | 
			
		||||
						if (newExp.Arguments.Count == 0) return "(NULL)";
 | 
			
		||||
						if (typeof(IEnumerable).IsAssignableFrom(newExp.Arguments[0].Type) == false) return "(NULL)";
 | 
			
		||||
						return getExp(newExp.Arguments[0]);
 | 
			
		||||
					}
 | 
			
		||||
					return null;
 | 
			
		||||
			}
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
using FreeSql.Internal;
 | 
			
		||||
using FreeSql.Internal.Model;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Linq.Expressions;
 | 
			
		||||
@@ -21,7 +22,7 @@ namespace FreeSql.SqlServer {
 | 
			
		||||
					if (objType?.FullName == "System.Byte[]") return null;
 | 
			
		||||
 | 
			
		||||
					var argIndex = 0;
 | 
			
		||||
					if (objType == null && callExp.Method.DeclaringType.FullName == typeof(Enumerable).FullName) {
 | 
			
		||||
					if (objType == null && callExp.Method.DeclaringType == typeof(Enumerable)) {
 | 
			
		||||
						objExp = callExp.Arguments.FirstOrDefault();
 | 
			
		||||
						objType = objExp?.Type;
 | 
			
		||||
						argIndex++;
 | 
			
		||||
@@ -29,7 +30,7 @@ namespace FreeSql.SqlServer {
 | 
			
		||||
					if (objType == null) objType = callExp.Method.DeclaringType;
 | 
			
		||||
					if (objType != null) {
 | 
			
		||||
						var left = objExp == null ? null : getExp(objExp);
 | 
			
		||||
						if (objType.IsArray == true) {
 | 
			
		||||
						if (objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
 | 
			
		||||
							switch (callExp.Method.Name) {
 | 
			
		||||
								case "Contains":
 | 
			
		||||
									//判断 in
 | 
			
		||||
@@ -46,7 +47,27 @@ namespace FreeSql.SqlServer {
 | 
			
		||||
						if (a > 0) arrSb.Append(",");
 | 
			
		||||
						arrSb.Append(getExp(arrExp.Expressions[a]));
 | 
			
		||||
					}
 | 
			
		||||
					if (arrSb.Length == 1) arrSb.Append("NULL");
 | 
			
		||||
					return arrSb.Append(")").ToString();
 | 
			
		||||
				case ExpressionType.ListInit:
 | 
			
		||||
					var listExp = exp as ListInitExpression;
 | 
			
		||||
					var listSb = new StringBuilder();
 | 
			
		||||
					listSb.Append("(");
 | 
			
		||||
					for (var a = 0; a < listExp.Initializers.Count; a++) {
 | 
			
		||||
						if (listExp.Initializers[a].Arguments.Any() == false) continue;
 | 
			
		||||
						if (a > 0) listSb.Append(",");
 | 
			
		||||
						listSb.Append(getExp(listExp.Initializers[a].Arguments.FirstOrDefault()));
 | 
			
		||||
					}
 | 
			
		||||
					if (listSb.Length == 1) listSb.Append("NULL");
 | 
			
		||||
					return listSb.Append(")").ToString();
 | 
			
		||||
				case ExpressionType.New:
 | 
			
		||||
					var newExp = exp as NewExpression;
 | 
			
		||||
					if (typeof(IList).IsAssignableFrom(newExp.Type)) {
 | 
			
		||||
						if (newExp.Arguments.Count == 0) return "(NULL)";
 | 
			
		||||
						if (typeof(IEnumerable).IsAssignableFrom(newExp.Arguments[0].Type) == false) return "(NULL)";
 | 
			
		||||
						return getExp(newExp.Arguments[0]);
 | 
			
		||||
					}
 | 
			
		||||
					return null;
 | 
			
		||||
			}
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
using FreeSql.Internal;
 | 
			
		||||
using FreeSql.Internal.Model;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Linq.Expressions;
 | 
			
		||||
@@ -21,7 +22,7 @@ namespace FreeSql.Sqlite {
 | 
			
		||||
					if (objType?.FullName == "System.Byte[]") return null;
 | 
			
		||||
 | 
			
		||||
					var argIndex = 0;
 | 
			
		||||
					if (objType == null && callExp.Method.DeclaringType.FullName == typeof(Enumerable).FullName) {
 | 
			
		||||
					if (objType == null && callExp.Method.DeclaringType == typeof(Enumerable)) {
 | 
			
		||||
						objExp = callExp.Arguments.FirstOrDefault();
 | 
			
		||||
						objType = objExp?.Type;
 | 
			
		||||
						argIndex++;
 | 
			
		||||
@@ -29,7 +30,7 @@ namespace FreeSql.Sqlite {
 | 
			
		||||
					if (objType == null) objType = callExp.Method.DeclaringType;
 | 
			
		||||
					if (objType != null) {
 | 
			
		||||
						var left = objExp == null ? null : getExp(objExp);
 | 
			
		||||
						if (objType.IsArray == true) {
 | 
			
		||||
						if (objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
 | 
			
		||||
							switch (callExp.Method.Name) {
 | 
			
		||||
								case "Contains":
 | 
			
		||||
									//判断 in
 | 
			
		||||
@@ -46,7 +47,27 @@ namespace FreeSql.Sqlite {
 | 
			
		||||
						if (a > 0) arrSb.Append(",");
 | 
			
		||||
						arrSb.Append(getExp(arrExp.Expressions[a]));
 | 
			
		||||
					}
 | 
			
		||||
					if (arrSb.Length == 1) arrSb.Append("NULL");
 | 
			
		||||
					return arrSb.Append(")").ToString();
 | 
			
		||||
				case ExpressionType.ListInit:
 | 
			
		||||
					var listExp = exp as ListInitExpression;
 | 
			
		||||
					var listSb = new StringBuilder();
 | 
			
		||||
					listSb.Append("(");
 | 
			
		||||
					for (var a = 0; a < listExp.Initializers.Count; a++) {
 | 
			
		||||
						if (listExp.Initializers[a].Arguments.Any() == false) continue;
 | 
			
		||||
						if (a > 0) listSb.Append(",");
 | 
			
		||||
						listSb.Append(getExp(listExp.Initializers[a].Arguments.FirstOrDefault()));
 | 
			
		||||
					}
 | 
			
		||||
					if (listSb.Length == 1) listSb.Append("NULL");
 | 
			
		||||
					return listSb.Append(")").ToString();
 | 
			
		||||
				case ExpressionType.New:
 | 
			
		||||
					var newExp = exp as NewExpression;
 | 
			
		||||
					if (typeof(IList).IsAssignableFrom(newExp.Type)) {
 | 
			
		||||
						if (newExp.Arguments.Count == 0) return "(NULL)";
 | 
			
		||||
						if (typeof(IEnumerable).IsAssignableFrom(newExp.Arguments[0].Type) == false) return "(NULL)";
 | 
			
		||||
						return getExp(newExp.Arguments[0]);
 | 
			
		||||
					}
 | 
			
		||||
					return null;
 | 
			
		||||
			}
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user