When I run my application and I click a specific button I get the error:
\"The \"X\" property on \"Y\" could not be set to a \'null\' value. You must set thi
For me the following Steps corrected the Error:
"The "X" property on "Y" could not be set to a 'null' value. You must set this property to a non-null value of type 'Int32'."
In your EDMX, if you go under your Y table and click on X column, right-click, click on Properties, scroll down to Nullable
and change from False
to True
.
If you get a "mapping fragment" error, you'll have to delete the table from the EDMX and re-add it, because in the Model Browser it stores the table properties and the only way to refresh that (that I know of) is to delete the table from the Model Browser under <database>.Store
then retrieving it using Update Model from Database..
command.
This may happen when the database table allows NULL and there are records that have a null value and you try to read this record with EF and the mapping class does not allow a null value.
The solution is either change the database table so that it does not allow null or change your class to allow null.
In my case in created view in DB column that I select that contains null value I change that value by this select statement:
Before my change
select
..., GroupUuId , ..
after my change
select
..., ISNULL(GroupUuId, 0), ...
Sorry for my bad English
I just replace data type int
to int32?
public Int32 Field{ get; set; }
to
public Int32? Field{ get; set; }
and the problem is solved