实体框架代码优先模型构建者

问题描述 投票:0回答:1

在我的DbContext课上,我有以下内容:

void OnModelCreating(DbModelBuilder modelBuilder)
{
   modelBuilder.Properties<string>().Configure(c => { c.HasMaxLength(250); });
}

而且也在我拥有的特定模型的EntityTypeConfiguration类内部:

{
   Property(p => p.Name).HasMaxLength(500);
}

问题是,在Configuration类中将属性设置为500无效,并且EF仍在验证最大值为250。

我如何将常规设置设置为250,但需要在每个类中使用流利的api覆盖?

c# entity-framework entity-framework-6 ef-code-first ef-fluent-api
1个回答
-1
投票

@@ Lutti Coelho:我的错

在下面的OnModelCreating方法中添加代码

modelBuilder.Entity<Student>()
                    .Property(p => p.StudentName)
                    .HasMaxLength(50);
© www.soinside.com 2019 - 2024. All rights reserved.