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:
@ -33,9 +33,9 @@ namespace FreeSql.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 is JToken || param is JObject || param is JArray))
|
||||
param = Utils.GetDataReaderValue(mapType, param);
|
||||
bool isdic = false;
|
||||
bool isdic;
|
||||
if (param is bool || param is bool?)
|
||||
return (bool)param ? "'t'" : "'f'";
|
||||
else if (param is string || param is char)
|
||||
|
@ -104,14 +104,15 @@ namespace FreeSql.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;
|
||||
switch (objType.FullName)
|
||||
{
|
||||
case "Newtonsoft.Json.Linq.JToken":
|
||||
case "Newtonsoft.Json.Linq.JObject":
|
||||
case "Newtonsoft.Json.Linq.JArray":
|
||||
left = objExp == null ? null : getExp(objExp);
|
||||
switch (callExp.Method.Name)
|
||||
{
|
||||
case "Any": return $"(jsonb_array_length(coalesce({left},'[]')) > 0)";
|
||||
@ -137,6 +138,7 @@ namespace FreeSql.PostgreSQL
|
||||
}
|
||||
if (objType.FullName == typeof(Dictionary<string, string>).FullName)
|
||||
{
|
||||
left = objExp == null ? null : getExp(objExp);
|
||||
switch (callExp.Method.Name)
|
||||
{
|
||||
case "Contains":
|
||||
@ -154,24 +156,30 @@ namespace FreeSql.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(')')}]";
|
||||
@ -180,6 +188,7 @@ namespace FreeSql.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";
|
||||
}
|
||||
@ -494,7 +503,7 @@ namespace FreeSql.PostgreSQL
|
||||
case "AddTicks": return $"(({left})::timestamp+(({args1})/10||' microseconds')::interval)";
|
||||
case "AddYears": return $"(({left})::timestamp+(({args1})||' year')::interval)";
|
||||
case "Subtract":
|
||||
switch ((exp.Arguments[0].Type.IsNullableType() ? exp.Arguments[0].Type.GenericTypeArguments.FirstOrDefault() : exp.Arguments[0].Type).FullName)
|
||||
switch ((exp.Arguments[0].Type.IsNullableType() ? exp.Arguments[0].Type.GetGenericArguments().FirstOrDefault() : exp.Arguments[0].Type).FullName)
|
||||
{
|
||||
case "System.DateTime": return $"(extract(epoch from ({left})::timestamp-({args1})::timestamp)*1000000)";
|
||||
case "System.TimeSpan": return $"(({left})::timestamp-(({args1})||' microseconds')::interval)";
|
||||
|
Reference in New Issue
Block a user