Reputation: 1039
I can't save values into two nullable columns.
This is the entity I'm saving:
nquote_orderheaders header = new nquote_orderheaders()
{
CreatedDate = DateTime.Now,
SendDate = DateTime.Now,
SentByUser = accountInfo.Username,
CreatedByUser = accountInfo.Username,
QuoteOrderNumber = tempQuoteNumber,
IMCustomerNumber = resellerInfo.CustomerNo,
CustomerEmail = accountInfo.Username,
CustomerName = resellerInfo.CustomerName,
UserComment = "",
StatusId = 1,
CustomerId = data.CustomerId,
ExpirationDate = DateTime.Now.AddDays(14)
};
The SendDate and ExpirationDate fields are nullable Datetimes. They end up null in the database.
I'm using MySql with MySqlConnector 6.5.4. Any suggestions greatly appreciated.
Upvotes: 2
Views: 1912
Reputation:
You have to cast DateTime.Now
to the Nullable just like the following code:
CreatedDate = DateTime.Now as DateTime?,
or using longer form:
CreatedDate = DateTime.Now as Nullable<DateTime>,
Upvotes: 2