正价JsonTypeAttribute特性,标记该特性的数据会已json格式存储在数据库中。

This commit is contained in:
falcon 2023-03-14 16:18:20 +08:00
parent 456969b5dc
commit cf4c66b4cd
4 changed files with 49 additions and 11 deletions

View File

@ -0,0 +1,21 @@
using SqlSugar;
using System.Reflection;
namespace Falcon.SugarApi.DatabaseDefinitions.EntityServices
{
/// <summary>
/// 设置列以Json类型存储。
/// </summary>
public class JsonTypeColumnServices:IEntityColumnServices
{
/// <inheritdoc/>
public void SetupColumn(PropertyInfo p,EntityColumnInfo c) {
if(p.TryGetAttribute<JsonTypeAttribute>(out var a)) {
c.IsJson = true;
if(a.Length >= 0) {
c.Length = a.Length;
}
}
}
}
}

View File

@ -0,0 +1,16 @@
using System;
namespace Falcon.SugarApi.DatabaseDefinitions
{
/// <summary>
/// 表示该列将以json字符串形式存储
/// </summary>
[AttributeUsage(AttributeTargets.Property,AllowMultiple = false,Inherited = false)]
public class JsonTypeAttribute:Attribute
{
/// <summary>
/// 数据长度。默认4000
/// </summary>
public int Length { get; set; } = 4000;
}
}

View File

@ -35,6 +35,7 @@ namespace Falcon.SugarApi.DatabaseDefinitions
ColumnServices.Add(new SetupKeyColumnServices()); ColumnServices.Add(new SetupKeyColumnServices());
ColumnServices.Add(new SetupLengthColumnServices()); ColumnServices.Add(new SetupLengthColumnServices());
ColumnServices.Add(new SetupNullableColumnServices()); ColumnServices.Add(new SetupNullableColumnServices());
ColumnServices.Add(new JsonTypeColumnServices());
} }
/// <summary> /// <summary>