change all string property max length

后端 未结 1 1905
轮回少年
轮回少年 2020-12-19 07:11

In EF 6 I can do something like this:

modelBuilder
  .Properties()
  .Where(p => p.PropertyType == typeof(string) && 
              p.GetCustomAtt         


        
1条回答
  •  温柔的废话
    2020-12-19 08:00

    I suppose this to be one of the "still lacking" functionalities in EF Core and expect it to be added in some later version.

    Until then, the closest I can suggest (for v1.1.0) is as follows:

    foreach (var p in modelBuilder.Model
        .GetEntityTypes()
        .SelectMany(t => t.GetProperties())
        .Where(p => p.ClrType == typeof(string) && p.GetMaxLength() == null))
    {
        p.SetMaxLength(2000);
    }
    

    0 讨论(0)
提交回复
热议问题