mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-17 19:43:21 +08:00
- 修复 pgsql IList -> JArray 映射;#1092
This commit is contained in:
parent
10d9090fb4
commit
a5723c1773
@ -538,14 +538,5 @@
|
||||
<param name="that"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.FreeSqlRepositoryDependencyInjection.AddFreeRepository(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{FreeSql.FluentDataFilter},System.Reflection.Assembly[])">
|
||||
<summary>
|
||||
批量注入 Repository,可以参考代码自行调整
|
||||
</summary>
|
||||
<param name="services"></param>
|
||||
<param name="globalDataFilter"></param>
|
||||
<param name="assemblies"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
@ -14,6 +14,16 @@
|
||||
编号
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Issues._1092.Test.Name">
|
||||
<summary>
|
||||
会员ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Issues._1092.Test.Ids">
|
||||
<summary>
|
||||
会员ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Tests.Issues._467.PayOrder.Money">
|
||||
<summary>
|
||||
收款金额
|
||||
|
66
FreeSql.Tests/FreeSql.Tests/Issues/1092.cs
Normal file
66
FreeSql.Tests/FreeSql.Tests/Issues/1092.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using FreeSql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NpgsqlTypes;
|
||||
using Npgsql.LegacyPostgis;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Threading;
|
||||
using System.Data.SqlClient;
|
||||
using kwlib;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace FreeSql.Tests.Issues
|
||||
{
|
||||
public class _1092
|
||||
{
|
||||
[Fact]
|
||||
public void JsonbTest()
|
||||
{
|
||||
var fsql = g.pgsql;
|
||||
fsql.Delete<Test>().Where("1=1").ExecuteAffrows();
|
||||
|
||||
var model = new Test() { Name = "hahahah", Ids = new List<long> { 22 } };
|
||||
|
||||
var json1 = JsonConvert.SerializeObject(new List<long> { 22 });
|
||||
var jarray1 = JArray.FromObject(new List<long> { 22 });
|
||||
|
||||
//异常:
|
||||
/*
|
||||
* Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'System.String'.”
|
||||
*/
|
||||
var insertAndOut = fsql.Insert(model)
|
||||
.ExecuteInserted();
|
||||
|
||||
//异常,和ExecuteInserted一样的错误
|
||||
var updateResult = fsql.Update<Test>()
|
||||
.SetSource(model)
|
||||
.ExecuteUpdated();
|
||||
}
|
||||
|
||||
[Table(Name = "public.test_issues_1092")]
|
||||
public class Test
|
||||
{
|
||||
[Column(Name = "id", IsPrimary = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 会员ID
|
||||
/// </summary>
|
||||
[Column(Name = "name")]
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 会员ID
|
||||
/// </summary>
|
||||
[Column(Name = "ids", MapType = typeof(JArray))]
|
||||
public List<long> Ids { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ using System.Data.Common;
|
||||
using System.Linq.Expressions;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
|
||||
namespace FreeSql.PostgreSQL
|
||||
@ -70,6 +71,7 @@ namespace FreeSql.PostgreSQL
|
||||
var MethodJObjectParse = typeof(JObject).GetMethod("Parse", new[] { typeof(string) });
|
||||
var MethodJArrayParse = typeof(JArray).GetMethod("Parse", new[] { typeof(string) });
|
||||
var MethodJsonConvertDeserializeObject = typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string), typeof(Type) });
|
||||
var MethodToString = typeof(Utils).GetMethod("ToStringConcat", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(object) }, null);
|
||||
Utils.GetDataReaderValueBlockExpressionSwitchTypeFullName.Add((LabelTarget returnTarget, Expression valueExp, Type type) =>
|
||||
{
|
||||
switch (type.FullName)
|
||||
@ -95,7 +97,10 @@ namespace FreeSql.PostgreSQL
|
||||
return Expression.Return(returnTarget, valueExp);
|
||||
}
|
||||
if (typeof(IList).IsAssignableFrom(type))
|
||||
return Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJsonConvertDeserializeObject, Expression.Convert(valueExp, typeof(string)), Expression.Constant(type, typeof(Type))), type));
|
||||
return Expression.IfThenElse(
|
||||
Expression.TypeIs(valueExp, typeof(string)),
|
||||
Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJsonConvertDeserializeObject, Expression.Convert(valueExp, typeof(string)), Expression.Constant(type, typeof(Type))), type)),
|
||||
Expression.Return(returnTarget, Expression.TypeAs(Expression.Call(MethodJsonConvertDeserializeObject, Expression.Convert(Expression.Call(MethodToString, valueExp), typeof(string)), Expression.Constant(type, typeof(Type))), type)));
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user