这是我的 POCO
public class Game
{
public Guid Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Galaxy> Galaxies { get; set; }
}
这是 TypeConfiguration ....
public class GameConfiguration : EntityTypeConfiguration<Game>
{
public GameConfiguration()
{
HasKey(x => x.Id);
Property(x => x.Id).HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity);
HasMany(x => x.Galaxies);
Property(x => x.Name)
.IsRequired()
.HasMaxLength(50);
}
}
我的问题是......为什么,当它作为迁移添加时,迁移代码不会将“名称”属性设置为“非空”?它也忽略了 MaxLength 设置。为什么是这样?
CreateTable(
"dbo.Games",
c => new
{
Id = c.Guid(nullable: false),
Name = c.String(),
})
.PrimaryKey(t => t.Id);