@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user