正价JsonTypeAttribute特性,标记该特性的数据会已json格式存储在数据库中。
This commit is contained in:
parent
456969b5dc
commit
cf4c66b4cd
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
Falcon.SugarApi/DatabaseDefinitions/JsonTypeAttribute.cs
Normal file
16
Falcon.SugarApi/DatabaseDefinitions/JsonTypeAttribute.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user