重写sqlsugar判断列长度的方法
This commit is contained in:
parent
eb66061fa2
commit
128f5f6025
|
@ -1,4 +1,5 @@
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -9,22 +10,19 @@ namespace Falcon.SugarApi.DatabaseDefinitions.EntityServices
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置长度规则
|
/// 设置长度规则
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SetupLengthColumnServices : IEntityColumnServices
|
public class SetupLengthColumnServices:IEntityColumnServices
|
||||||
{
|
{
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void SetupColumn(PropertyInfo p, EntityColumnInfo c) {
|
public void SetupColumn(PropertyInfo p,EntityColumnInfo c) {
|
||||||
var len = new List<int>();
|
var len = new List<int> { };
|
||||||
if (p.TryGetAttribute<StringLengthAttribute>(out var sl)) {
|
if(p.TryGetAttribute<StringLengthAttribute>(out var sl)) {
|
||||||
len.Add(sl.MaximumLength);
|
len.Add(sl.MaximumLength);
|
||||||
}
|
}
|
||||||
if (p.TryGetAttribute<MaxLengthAttribute>(out var la)) {
|
if(p.TryGetAttribute<MaxLengthAttribute>(out var la)) {
|
||||||
len.Add(la.Length);
|
len.Add(la.Length);
|
||||||
}
|
}
|
||||||
if (p.TryGetAttribute<SugarColumn>(out var sc)) {
|
if(len.Any()) {
|
||||||
len.Add(sc.Length);
|
c.Length=len.Reduce(c.Length,(m,i) => Math.Max(m,i));
|
||||||
}
|
|
||||||
if (len.Any()) {
|
|
||||||
c.Length = len.Max();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user