我会先从下面的代码中按代码添加NOT NULL NVARCHAR列:
I would add a NOT NULL NVARCHAR column by code first from below code:
public class ApplicationUser : IdentityUser { [Required, MaxLength(10), MinLength(5)] public string StaffCode { get; set; } }然后我运行添加迁移用户 在Nuget控制台上,
Then i run "Add-Migration User" on Nuget console,
它将在下面生成迁移类:
It generate the migrate class below:
public partial class abc : DbMigration { public override void Up() { AlterColumn("dbo.AspNetUsers", "StaffCode", c => c.String(maxLength: 10)); } public override void Down() { AlterColumn("dbo.AspNetUsers", "StaffCode", c => c.String()); } }最小长度:5 并且 nullable:false 不见了。 我称之为手动添加并更新到数据库,但这似乎不合理。
The minlength:5 and nullable:false is gone. I call add it manually and update to database, but it seems not reasonable.
谢谢。
推荐答案我会回答我的问题。 i找到该帖子: blogs.msdn/b/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx
I would answer my question. i find that post: blogs.msdn/b/alexj/archive/2009/04/15/tip-12-choosing-an-inheritance-strategy.aspx
默认情况下,EF6使用 TPH ,不允许将列设置为NOT NULL。 请考虑每种类型的表(TPT)或每种具体类别的表(TPC)
By default EF6 using TPH ,which not allow set the column to NOT NULL. Please conside Table Per Type (TPT) or Table Per Concrete Class (TPC)
更多推荐
EF6 Add
发布评论