简体   繁体   English

在生产中首先使列可为空 EF 6 代码

[英]make column nullable EF 6 Code first in production

I have a web api application using sql server EF 6 code first approach and it's up and running.我有一个 web api 应用程序使用 sql 服务器 EF 6 代码优先方法,它已启动并正在运行。

Now for a table I want to make a column NULL.现在对于一个表,我想创建一个列 NULL。

From sql server database side I alter my table definition and able to make the column NULL.从 sql 服务器数据库端,我更改了我的表定义并能够创建列 NULL。

But the class definition has [Required] attribute, which is the reason database save (with null value) still failing even I made database column NULL.但是 class 定义具有[Required]属性,这就是数据库保存(具有 null 值)仍然失败的原因,即使我创建了数据库列 NULL。

 [Required]
    [StringLength(512)]
    public string Name { get; set; }

I there any solution here?我这里有什么解决办法吗?

I understand I need to remove [Required] attribute and this requires a code change.我知道我需要删除[Required]属性,这需要更改代码。 I am looking if some way without code change.我正在寻找没有代码更改的某种方式。 this is production.这是生产。

Removing Required attribute删除 Required 属性

[StringLength(512)]
public string Name {get;set;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM