As I experienced today, there’s a bug in the Entity Framework. Let’s have a look at the following scenario:
In Screenshot 1 you can see a table with two datetime columns. One is marked as nullable whereas the other is not. I used Database First approach to generate the Entity Data Model. Screenshot 2 shows you the auto-generated Entity. Take a look at the following properties:
Notice the highlighted setting “Nullable” of the generated property “MyNullableDateTime”: It’s none instead of what it should be – true. Nevertheless, the generated code is all fine:
Unfortunately, if you change the column in the database to be no longer nullable and furthermore, you refresh your model, this will cause a build error:
>>Error 3031: Problem in mapping fragments starting at line 51:Non-nullable column >>DateTimeTest.MyNullableDateTime in table DateTimeTest is mapped to a nullable entity property.
Mit Tag(s) versehen: EntityFramework