增加codefirst迁移配置
continuous-integration/drone/push Build is passing

This commit is contained in:
hang
2024-09-17 14:26:12 +08:00
parent 5990477fdc
commit ab68a63bdd
20 changed files with 928 additions and 1006 deletions
@@ -11,6 +11,12 @@ namespace IRaCIS.Core.Test.CodeFirstTest.PGSQL.Migrations
/// </summary>
public class MaxStringLengthConvention : IModelFinalizingConvention
{
private readonly int _defaultLenth;
public MaxStringLengthConvention(int defaultLenth)
{
_defaultLenth = defaultLenth;
}
public void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConventionContext<IConventionModelBuilder> context)
{
foreach (var property in modelBuilder.Metadata.GetEntityTypes()
@@ -31,17 +37,17 @@ namespace IRaCIS.Core.Test.CodeFirstTest.PGSQL.Migrations
// 输出调试信息,看看是哪种特性生效
if (stringLengthAttribute != null)
{
Console.WriteLine($"{property.Name}: StringLength({stringLengthAttribute.MaximumLength})");
//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)");
//Console.WriteLine($"{property.Name}: MaxLength (no specific length, allowing max)");
}
else
{
Console.WriteLine($"{property.Name}: Default length 200");
property.Builder.HasMaxLength(200);
//Console.WriteLine($"{property.Name}: Default length {_defaultLenth}");
property.Builder.HasMaxLength(_defaultLenth);
}
}
}