什么是改变可空,而不是空数据类型的数据注解? [英] What is the data annotation for changing nullable and not null data types?

查看:144
本文介绍了什么是改变可空,而不是空数据类型的数据注解?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这应该是简单的有经验的程序员,但在这里不言而喻。我使用实体框架code first.I也使迁移,并设置为自动(可爱的功能)。

I reckon this should be simple for experienced programmers but here it goes. I am working on a project using entity framework code first.I have also enabled migrations and set to auto (Lovely feature).

我愣神声明的数据类型错在我的实体类之一,现在我意识到,它不会有什么,我试图做的工作。一定是自动完成功能。但不管怎么说,本场是为空的,现在,我已经改成了我想要的东西,它设置字段为不空。

I stupidly declared one of the datatype wrong in my entity class and now i realised that it wouldn't work with what i was trying to do. Must have been the auto complete feature. But anyways, the field was nullable and now that i have changed it to what i want, it has set the field to "not null".

最初: public虚拟字节[] {的ImageData获得;组; }

更改为: public虚拟字节的ImageData {搞定;组; }

现在,我已经改变和建造的解决方案,更新数据库-force 将无法正常工作,并抛出一个错误是:

Now that i have changed and built the solution, update-database -force will not work and throws an error that:

Cannot insert the value NULL into column 'ImageData', column does not allow nulls. UPDATE fails. The statement has been terminated.

有一个数据注解我可以用它来设置这个领域回可为空?

Is there a Data Annotation i could use to set this field back to nullable?

例如: [数据类型(DataType.Upload)]

我已经通过这里找了一个相当长的时间,我似乎无法找到我所期待的。

I have looked through here for a considerable amount of time and i can't seem to find what i am looking for.

推荐答案

更改属性类型的空形式字节?

Change the property type to the nullable form byte?.

public virtual byte? ImageData { get; set; }

这篇关于什么是改变可空,而不是空数据类型的数据注解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆