Entity Framework does not claim datetime.now is null

Here is my code:

UVCUpdate update = new UVCUpdate();
update.CurrentDate = DateTime.Now;
_context.UVCUpdates.Add(update);

_context.SaveChanges();

Now I get an internal exception by saying this:

Cannot insert a NULL value in the column "CurrentDate", table "bLinked.dbo.BlackbookUpdateUVC"; column does not allow zeros. INSERT does not work.

If I print DateTime.Now right before this code, it produces:

11/15/2016 7:26:35 PM

My data type for CurrentDate in db is set to datetime, and in the class is DateTime. Not to allow null, but DateTime.Now should not have a null value?

+4
source share
2 answers

, " " EF . Identity Computed - , EF , , INSERT UPDATE. NULL , - , .

+1

, , . Leopard.

, UVCUpdate, , , , [DatabaseGenerated(DatabaseGeneratedOption.Identity)] CurrentDate. , , SQL, SQL , , null. CurrentDate , ...

0

Source: https://habr.com/ru/post/1654692/


All Articles