EF6 Add

编程入门 行业动态 更新时间:2024-10-21 04:59:11
本文介绍了EF6 Add-Migration是否不能为空字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我会先从下面的代码中按代码添加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

本文发布于:2023-11-15 03:50:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1590882.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Add

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!