Reputation: 3522
EF is making some properties non nullable by default in the database, is there some way to over ride this for certain properties ? I tried searching for a data annotation but found nothing.
I am using code first the properties are an int and a datetime
Upvotes: 0
Views: 139
Reputation: 67135
I am assuming that you are using code-first. You are probably getting non-nullable for types that are indeed non-nullable (value types), like int, bool, etc. You need to use the nullable version of these in order to do this:
int? MyColumnThatIsNullable
and NOT this
int MyColumnThatIsNOTNullable
Think about how the code would work and this will make sense to you. If a field is an int and a null is attempted to be passed into the code, then you will either have some sort of error, or a magic (default) value. This will not properly represent the value in the database. So, if you use the nullable version, then the null in the database can be represented for what it truly is, a null.
Upvotes: 4