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'

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'

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

Trying to set a non-null string to type 'System.Int32'

Just for anyone else having issues with this. Set a breakpoint in DatabaseContext and make sure it's connecting to the correct database. Mine was being overwritten from a web.config file I forgot about.

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

DateTime is a reference type. You need to use Nullable DateTime in your class.

DateTime? ResolveDate = null;

or

Nullable<DateTime> ResolveDate ;

InvalidOperationException You must set this property to a non-null value of type string

I had a similar issue but for byte to bool

I edited my entity

public byte XX { get; set; }
Then edited my Model to have
public bool XX { get; set; }

used auto mapper to map them together and it fixed the issue i was having, try this with editing your Model to a string and map it accordingly.

i am using code first for my existing databases, but it may work for db first



Related Topics



Leave a reply



Submit