diff --git a/Falcon.SugarApi/DatabaseDefinitions/EntityServices/JsonTypeColumnServices.cs b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/JsonTypeColumnServices.cs
new file mode 100644
index 0000000..11972f5
--- /dev/null
+++ b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/JsonTypeColumnServices.cs
@@ -0,0 +1,21 @@
+using SqlSugar;
+using System.Reflection;
+
+namespace Falcon.SugarApi.DatabaseDefinitions.EntityServices
+{
+ ///
+ /// 设置列以Json类型存储。
+ ///
+ public class JsonTypeColumnServices:IEntityColumnServices
+ {
+ ///
+ public void SetupColumn(PropertyInfo p,EntityColumnInfo c) {
+ if(p.TryGetAttribute(out var a)) {
+ c.IsJson = true;
+ if(a.Length >= 0) {
+ c.Length = a.Length;
+ }
+ }
+ }
+ }
+}
diff --git a/Falcon.SugarApi/DatabaseDefinitions/EntityServices/SetupLengthColumnServices.cs b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/SetupLengthColumnServices.cs
index 7661087..2f653de 100644
--- a/Falcon.SugarApi/DatabaseDefinitions/EntityServices/SetupLengthColumnServices.cs
+++ b/Falcon.SugarApi/DatabaseDefinitions/EntityServices/SetupLengthColumnServices.cs
@@ -22,7 +22,7 @@ namespace Falcon.SugarApi.DatabaseDefinitions.EntityServices
len.Add(la.Length);
}
if(len.Any()) {
- c.Length=len.Reduce(c.Length,(m,i) => Math.Max(m,i));
+ c.Length = len.Reduce(c.Length,(m,i) => Math.Max(m,i));
}
}
}
diff --git a/Falcon.SugarApi/DatabaseDefinitions/JsonTypeAttribute.cs b/Falcon.SugarApi/DatabaseDefinitions/JsonTypeAttribute.cs
new file mode 100644
index 0000000..ebcd15d
--- /dev/null
+++ b/Falcon.SugarApi/DatabaseDefinitions/JsonTypeAttribute.cs
@@ -0,0 +1,16 @@
+using System;
+
+namespace Falcon.SugarApi.DatabaseDefinitions
+{
+ ///
+ /// 表示该列将以json字符串形式存储
+ ///
+ [AttributeUsage(AttributeTargets.Property,AllowMultiple = false,Inherited = false)]
+ public class JsonTypeAttribute:Attribute
+ {
+ ///
+ /// 数据长度。默认4000
+ ///
+ public int Length { get; set; } = 4000;
+ }
+}
diff --git a/Falcon.SugarApi/DatabaseDefinitions/SugarConnectionConfig.cs b/Falcon.SugarApi/DatabaseDefinitions/SugarConnectionConfig.cs
index 5064eeb..316021b 100644
--- a/Falcon.SugarApi/DatabaseDefinitions/SugarConnectionConfig.cs
+++ b/Falcon.SugarApi/DatabaseDefinitions/SugarConnectionConfig.cs
@@ -13,7 +13,7 @@ namespace Falcon.SugarApi.DatabaseDefinitions
///
/// SqlSugar数据库连接配置
///
- public class SugarConnectionConfig : ConnectionConfig
+ public class SugarConnectionConfig:ConnectionConfig
{
///
/// 是否使用log
@@ -35,6 +35,7 @@ namespace Falcon.SugarApi.DatabaseDefinitions
ColumnServices.Add(new SetupKeyColumnServices());
ColumnServices.Add(new SetupLengthColumnServices());
ColumnServices.Add(new SetupNullableColumnServices());
+ ColumnServices.Add(new JsonTypeColumnServices());
}
///
@@ -42,14 +43,14 @@ namespace Falcon.SugarApi.DatabaseDefinitions
///
public SugarConnectionConfig() {
this.ConfigureExternalServices ??= new ConfigureExternalServices { };
- this.ConfigureExternalServices.EntityNameService = (t, e) => {
- foreach (var i in TableServices) {
- i.SetupTable(t, e);
+ this.ConfigureExternalServices.EntityNameService = (t,e) => {
+ foreach(var i in TableServices) {
+ i.SetupTable(t,e);
}
};
- this.ConfigureExternalServices.EntityService = (p, c) => {
- foreach (var i in ColumnServices) {
- i.SetupColumn(p, c);
+ this.ConfigureExternalServices.EntityService = (p,c) => {
+ foreach(var i in ColumnServices) {
+ i.SetupColumn(p,c);
}
};
}
@@ -67,7 +68,7 @@ namespace Falcon.SugarApi.DatabaseDefinitions
/// 通过配置实现Redis缓冲,必须单例实现.
///
public void AddRedisCache(string connectionString) {
- if (connectionString.IsNullOrEmpty()) {
+ if(connectionString.IsNullOrEmpty()) {
AddRedisCache();
return;
}
@@ -88,9 +89,9 @@ namespace Falcon.SugarApi.DatabaseDefinitions
///
/// 缓存提供程序
/// 序列化实现
- public void AddDistributedCache(IDistributedCache cache, IJsonSerialize serialize) {
+ public void AddDistributedCache(IDistributedCache cache,IJsonSerialize serialize) {
this.ConfigureExternalServices ??= new ConfigureExternalServices { };
- this.ConfigureExternalServices.DataInfoCacheService = new DistributedCache(cache, serialize);
+ this.ConfigureExternalServices.DataInfoCacheService = new DistributedCache(cache,serialize);
}
}
}