Skip to content

Commit 0a9c685

Browse files
committed
- 优化 pgsql + JsonMap 自动映射为 jsonb;#2060
1 parent 083166c commit 0a9c685

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Examples/base_entity/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3498,7 +3498,7 @@ class Table11
34983498
{
34993499
public int Id { get; set; }
35003500

3501-
[JsonMap, Column(DbType = "json")]
3501+
[JsonMap]
35023502
public TableOptions Options { get; set; }
35033503
}
35043504
class TableOptions

Extensions/FreeSql.Extensions.JsonMap/JsonMapCore.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using FreeSql.DataAnnotations;
33
using FreeSql.Internal.CommonProvider;
44
using Newtonsoft.Json;
5+
using Newtonsoft.Json.Linq;
56
using System;
67
using System.Collections.Concurrent;
78
using System.Collections.Generic;
@@ -62,8 +63,16 @@ public static void UseJsonMap(this IFreeSql fsql, JsonSerializerSettings setting
6263

6364
if (e.ModifyResult.MapType == null)
6465
{
65-
e.ModifyResult.MapType = typeof(string);
66-
e.ModifyResult.StringLength = -2;
66+
switch (fsql.Ado.DataType)
67+
{
68+
case DataType.PostgreSQL:
69+
e.ModifyResult.MapType = typeof(JObject);
70+
break;
71+
default:
72+
e.ModifyResult.MapType = typeof(string);
73+
e.ModifyResult.StringLength = -2;
74+
break;
75+
}
6776
}
6877
if (_dicTypes.TryAdd(e.Property.PropertyType, true))
6978
{

0 commit comments

Comments
 (0)