0
votes

Logging caught an error in our application which I have been unable to reproduce. It did, however, catch the message which was:

The 'MyProperty' property on 'MyTable' could not be set to a 'null' value. You must set this property to a non-null value of type 'System.Int32'.

Which is fine, except that the 'MyProperty' property is certainly nullable. It's set to nullable in the table.

[MyProperty] [int] NULL,

And in the EDMX file for Entity Framework, Nullable was set to (None) but the Entity itself shows the property as nullable:

public Nullable<int> MyProperty { get; set; }

Intellisense shows this as int? when creating Entities of this class.

Why is the system complaining about setting this field to null?

1
May be in your model it is null-able but what it is in your database. Or Do you have Fluent API configuration for this entity? - TanvirArjel
@TanvirArjel As the question states, I've checked the database and it's set to Null - Bob Tway
What about Fluent API? - TanvirArjel
@TanvirArjel We're not using fluent - Bob Tway
Then its really misterious ! - TanvirArjel

1 Answers

0
votes

Even though the Entity generate had Nullable<int> for the property, setting it to Nullable = true in the EDMX seems to have fixed the problem.