mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
- 补充 Expression IEnumerable<T>.Contains 的支持,之前只能数组或IList<T>;
This commit is contained in:
@ -42,5 +42,10 @@ namespace FreeSql.DataAnnotations {
|
||||
/// 数据库默认值
|
||||
/// </summary>
|
||||
internal object DbDefautValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 类型映射,比如:可将 enum 属性映射成 typeof(string)
|
||||
/// </summary>
|
||||
public Type Mapping { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -90,14 +90,12 @@ namespace FreeSql.MySql {
|
||||
argIndex++;
|
||||
}
|
||||
if (objType == null) objType = callExp.Method.DeclaringType;
|
||||
if (objType != null) {
|
||||
if (objType != null || objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
|
||||
var left = objExp == null ? null : getExp(objExp);
|
||||
if (objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
|
||||
switch (callExp.Method.Name) {
|
||||
case "Contains":
|
||||
//判断 in
|
||||
return $"({getExp(callExp.Arguments[argIndex])}) in {left}";
|
||||
}
|
||||
switch (callExp.Method.Name) {
|
||||
case "Contains":
|
||||
//判断 in
|
||||
return $"({getExp(callExp.Arguments[argIndex])}) in {left}";
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -90,14 +90,12 @@ namespace FreeSql.Oracle {
|
||||
argIndex++;
|
||||
}
|
||||
if (objType == null) objType = callExp.Method.DeclaringType;
|
||||
if (objType != null) {
|
||||
if (objType != null || objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
|
||||
var left = objExp == null ? null : getExp(objExp);
|
||||
if (objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
|
||||
switch (callExp.Method.Name) {
|
||||
case "Contains":
|
||||
//判断 in
|
||||
return $"({getExp(callExp.Arguments[argIndex])}) in {left}";
|
||||
}
|
||||
switch (callExp.Method.Name) {
|
||||
case "Contains":
|
||||
//判断 in
|
||||
return $"({getExp(callExp.Arguments[argIndex])}) in {left}";
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -95,7 +95,7 @@ namespace FreeSql.PostgreSQL {
|
||||
argIndex++;
|
||||
}
|
||||
if (objType == null) objType = callExp.Method.DeclaringType;
|
||||
if (objType != null) {
|
||||
if (objType != null || objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
|
||||
var left = objExp == null ? null : getExp(objExp);
|
||||
switch (objType.FullName) {
|
||||
case "Newtonsoft.Json.Linq.JToken":
|
||||
@ -134,32 +134,30 @@ namespace FreeSql.PostgreSQL {
|
||||
case "Values": return $"avals({left})";
|
||||
}
|
||||
}
|
||||
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(')')}]";
|
||||
return $"(case when {left} is null then 0 else array_length({left},1) end > 0)";
|
||||
case "Contains":
|
||||
//判断 in 或 array @> array
|
||||
var right1 = getExp(callExp.Arguments[argIndex]);
|
||||
if (left.StartsWith("array[") || left.EndsWith("]"))
|
||||
return $"{right1} in ({left.Substring(6, left.Length - 7)})";
|
||||
if (left.StartsWith("(") || left.EndsWith(")"))
|
||||
return $"{right1} in {left}";
|
||||
if (right1.StartsWith("(") || right1.EndsWith(")")) right1 = $"array[{right1.TrimStart('(').TrimEnd(')')}]";
|
||||
return $"({left} @> array[{right1}])";
|
||||
case "Concat":
|
||||
if (left.StartsWith("(") || left.EndsWith(")")) left = $"array[{left.TrimStart('(').TrimEnd(')')}]";
|
||||
var right2 = getExp(callExp.Arguments[argIndex]);
|
||||
if (right2.StartsWith("(") || right2.EndsWith(")")) right2 = $"array[{right2.TrimStart('(').TrimEnd(')')}]";
|
||||
return $"({left} || {right2})";
|
||||
case "GetLength":
|
||||
case "GetLongLength":
|
||||
case "Length":
|
||||
case "Count":
|
||||
if (left.StartsWith("(") || left.EndsWith(")")) left = $"array[{left.TrimStart('(').TrimEnd(')')}]";
|
||||
return $"case when {left} is null then 0 else array_length({left},1) end";
|
||||
}
|
||||
switch (callExp.Method.Name) {
|
||||
case "Any":
|
||||
if (left.StartsWith("(") || left.EndsWith(")")) left = $"array[{left.TrimStart('(').TrimEnd(')')}]";
|
||||
return $"(case when {left} is null then 0 else array_length({left},1) end > 0)";
|
||||
case "Contains":
|
||||
//判断 in 或 array @> array
|
||||
var right1 = getExp(callExp.Arguments[argIndex]);
|
||||
if (left.StartsWith("array[") || left.EndsWith("]"))
|
||||
return $"{right1} in ({left.Substring(6, left.Length - 7)})";
|
||||
if (left.StartsWith("(") || left.EndsWith(")"))
|
||||
return $"{right1} in {left}";
|
||||
if (right1.StartsWith("(") || right1.EndsWith(")")) right1 = $"array[{right1.TrimStart('(').TrimEnd(')')}]";
|
||||
return $"({left} @> array[{right1}])";
|
||||
case "Concat":
|
||||
if (left.StartsWith("(") || left.EndsWith(")")) left = $"array[{left.TrimStart('(').TrimEnd(')')}]";
|
||||
var right2 = getExp(callExp.Arguments[argIndex]);
|
||||
if (right2.StartsWith("(") || right2.EndsWith(")")) right2 = $"array[{right2.TrimStart('(').TrimEnd(')')}]";
|
||||
return $"({left} || {right2})";
|
||||
case "GetLength":
|
||||
case "GetLongLength":
|
||||
case "Length":
|
||||
case "Count":
|
||||
if (left.StartsWith("(") || left.EndsWith(")")) left = $"array[{left.TrimStart('(').TrimEnd(')')}]";
|
||||
return $"case when {left} is null then 0 else array_length({left},1) end";
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -93,14 +93,12 @@ namespace FreeSql.SqlServer {
|
||||
argIndex++;
|
||||
}
|
||||
if (objType == null) objType = callExp.Method.DeclaringType;
|
||||
if (objType != null) {
|
||||
if (objType != null || objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
|
||||
var left = objExp == null ? null : getExp(objExp);
|
||||
if (objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
|
||||
switch (callExp.Method.Name) {
|
||||
case "Contains":
|
||||
//判断 in
|
||||
return $"({getExp(callExp.Arguments[argIndex])}) in {left}";
|
||||
}
|
||||
switch (callExp.Method.Name) {
|
||||
case "Contains":
|
||||
//判断 in
|
||||
return $"({getExp(callExp.Arguments[argIndex])}) in {left}";
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -90,14 +90,12 @@ namespace FreeSql.Sqlite {
|
||||
argIndex++;
|
||||
}
|
||||
if (objType == null) objType = callExp.Method.DeclaringType;
|
||||
if (objType != null) {
|
||||
if (objType != null || objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
|
||||
var left = objExp == null ? null : getExp(objExp);
|
||||
if (objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType)) {
|
||||
switch (callExp.Method.Name) {
|
||||
case "Contains":
|
||||
//判断 in
|
||||
return $"({getExp(callExp.Arguments[argIndex])}) in {left}";
|
||||
}
|
||||
switch (callExp.Method.Name) {
|
||||
case "Contains":
|
||||
//判断 in
|
||||
return $"({getExp(callExp.Arguments[argIndex])}) in {left}";
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Reference in New Issue
Block a user