修改测试迁移
continuous-integration/drone/push Build is passing

This commit is contained in:
hang
2024-09-12 23:51:51 +08:00
parent c9b1e5f92a
commit 603f6e095c
15 changed files with 616 additions and 107 deletions
@@ -1,5 +1,7 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace IRaCIS.Core.Test
@@ -17,7 +19,30 @@ namespace IRaCIS.Core.Test
.Where(
property => property.ClrType == typeof(string))))
{
property.Builder.HasMaxLength(200);
// 获取 MaxLength 特性
var maxLengthAttribute = property.PropertyInfo?.GetCustomAttributes(typeof(MaxLengthAttribute), false)
.FirstOrDefault() as MaxLengthAttribute;
// 获取 StringLength 特性
var stringLengthAttribute = property.PropertyInfo?.GetCustomAttributes(typeof(StringLengthAttribute), false)
.FirstOrDefault() as StringLengthAttribute;
// 输出调试信息,看看是哪种特性生效
if (stringLengthAttribute != null)
{
//Console.WriteLine($"{property.Name}: StringLength({stringLengthAttribute.MaximumLength})");
property.Builder.HasMaxLength(stringLengthAttribute.MaximumLength);
}
else if (maxLengthAttribute != null)
{
//Console.WriteLine($"{property.Name}: MaxLength (no specific length, allowing max)");
}
else
{
//Console.WriteLine($"{property.Name}: Default length 200");
property.Builder.HasMaxLength(200);
}
}
}
}