Saving a null date to SQL2008 via. SubSonic 2.x
Ok, So I am trying to set a datetime column to null via SubS开发者_高级运维onic 2.x
DateTime? dt = new DateTime();
dt= null;
Datum pd = (new DatumCollection()
.Where(Datum.Columns.Data, cp[0].Data)
.Load())[0];
pd.dtAcceptance = (DateTime)dt;
pd.Save();
Even though the database column allows for a null value, it won't save and I've tried a couple of other options, including setting it to DateTime.MinValue (1/1/0001 is too early a date I guess). I get 'Nullable object must have a value'
I've been searching here and Google for some magic bullet to fix what I think is a pretty stupid problem to have. Is there something in the SubSonic generation I need to change to allow it to work or do I have to write some stupid trigger on the SQL side that if a date comes in with '1/1/1900' to change it to NULL ?
help and thanks!
stack: "Nullable object must have a value." at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Nullable`1.get_Value() at Services.Decision.OnDecline(Int32 nParticipantID, Int32 nSessionID) in C:\dev\app\server\Services\Decision.cs:line 426
Ahh. You are casting dt to a DateTime, but you need to cast it to a nullable DateTime (DateTime?)
精彩评论