What is the data annotation for changing nullable and not null data types?

asp.net-mvc-4 c# ef-migrations entity-framework visual-studio-2012

Question

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".

Originally: public virtual Byte[] ImageData { get; set; }

Changed to: public virtual byte ImageData { get; set; }

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?

eg: [DataType(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.

1
2
10/21/2012 10:47:52 AM

Accepted Answer

Change the property type to the nullable form byte?.

public virtual byte? ImageData { get; set; }
6
10/21/2012 5:57:03 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow