mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 修复 MapType 属性的表达式解析 数组.Contains 得到是映射之前的值 bug;
- 修复 MapType 属性 与 IncludeMany 变异功能未映射处理的 bug;
This commit is contained in:
@ -32,7 +32,7 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
public override object AddslashesProcessParam(object param, Type mapType)
|
||||
{
|
||||
if (param == null) return "NULL";
|
||||
if (mapType != null && mapType != param.GetType())
|
||||
if (mapType != null && mapType != param.GetType() && (param is IEnumerable == false || mapType.IsArrayOrList()))
|
||||
param = Utils.GetDataReaderValue(mapType, param);
|
||||
if (param is bool || param is bool?)
|
||||
return (bool)param ? "'t'" : "'f'";
|
||||
|
@ -103,11 +103,12 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
argIndex++;
|
||||
}
|
||||
if (objType == null) objType = callExp.Method.DeclaringType;
|
||||
if (objType != null || objType.IsArray || typeof(IList).IsAssignableFrom(callExp.Method.DeclaringType))
|
||||
if (objType != null || objType.IsArrayOrList())
|
||||
{
|
||||
var left = objExp == null ? null : getExp(objExp);
|
||||
string left = null;
|
||||
if (objType.FullName == typeof(Dictionary<string, string>).FullName)
|
||||
{
|
||||
left = objExp == null ? null : getExp(objExp);
|
||||
switch (callExp.Method.Name)
|
||||
{
|
||||
case "Contains":
|
||||
@ -125,24 +126,30 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
switch (callExp.Method.Name)
|
||||
{
|
||||
case "Any":
|
||||
left = objExp == null ? null : getExp(objExp);
|
||||
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":
|
||||
tsc?.SetMapTypeTmp(null);
|
||||
var args1 = getExp(callExp.Arguments[argIndex]);
|
||||
var oldMapType = tsc?.SetMapTypeReturnOld(tsc?.mapTypeTmp);
|
||||
left = objExp == null ? null : getExp(objExp);
|
||||
tsc.SetMapTypeReturnOld(oldMapType);
|
||||
//判断 in 或 array @> array
|
||||
var right1 = getExp(callExp.Arguments[argIndex]);
|
||||
if (left.StartsWith("array[") || left.EndsWith("]"))
|
||||
return $"{right1} in ({left.Substring(6, left.Length - 7)})";
|
||||
return $"{args1} 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(')')}]";
|
||||
right1 = $"array[{right1}]";
|
||||
return $"{args1} in {left}";
|
||||
if (args1.StartsWith("(") || args1.EndsWith(")")) args1 = $"array[{args1.TrimStart('(').TrimEnd(')')}]";
|
||||
args1 = $"array[{args1}]";
|
||||
if (objExp != null)
|
||||
{
|
||||
var dbinfo = _common._orm.CodeFirst.GetDbInfo(objExp.Type);
|
||||
if (dbinfo.HasValue) right1 = $"{right1}::{dbinfo.Value.dbtype}";
|
||||
if (dbinfo.HasValue) args1 = $"{args1}::{dbinfo.Value.dbtype}";
|
||||
}
|
||||
return $"({left} @> {right1})";
|
||||
return $"({left} @> {args1})";
|
||||
case "Concat":
|
||||
left = objExp == null ? null : getExp(objExp);
|
||||
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(')')}]";
|
||||
@ -151,6 +158,7 @@ namespace FreeSql.Odbc.PostgreSQL
|
||||
case "GetLongLength":
|
||||
case "Length":
|
||||
case "Count":
|
||||
left = objExp == null ? null : getExp(objExp);
|
||||
if (left.StartsWith("(") || left.EndsWith(")")) left = $"array[{left.TrimStart('(').TrimEnd(')')}]";
|
||||
return $"case when {left} is null then 0 else array_length({left},1) end";
|
||||
}
|
||||
|
Reference in New Issue
Block a user