Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ - How to insert null DateTime into database column?

Using LINQ, how do I insert a null value into a SQL Server 2008 DateTime column?

The code below inserts "1/1/1900 12:00:00 AM", But I want to insert "NULL" instead

CreatDate = System.Data.SqlTypes.SqlDateTime.Null
like image 991
YingLi Zhuang Avatar asked Feb 23 '26 21:02

YingLi Zhuang


1 Answers

Ensure that the column in the DB is set to allow NULL and your entity property, "CreateDate" is defined as "DateTime? CreateDate {get;set;}". Then, simply set "CreateDate = null".

like image 78
Jason.Net Avatar answered Feb 25 '26 17:02

Jason.Net