We have a strange issue with DateOnly.MinValue in SQL Server 2017 and 2019.
su.PassportExpiryDate = DateOnly.MinValue;
PassportExpiryDate is of type DateOnly. In the database this column is of type DateTime2
.
Out of interest, we have set the following converter:
SqlServer2016Dialect.Provider.RegisterConverter<DateTime>(new SqlServerDateTime2Converter()); // map to DateTime2 sql type
However this gives us a SQL exception when we try save the object to the db.
System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
The SQL that is being generated is:
"UPDATE SystemUser" SET "IsDeleted"=@IsDeleted, "CreatedDate"=@CreatedDate, "FirstName"=@FirstName, "Surname"=@Surname, "MobileNumber"=@MobileNumber, "EmailAddress"=@EmailAddress, "ModifiedDate"=@ModifiedDate, "LastLoggedIn"=@LastLoggedIn, "UtcOffset"=@UtcOffset, "ConfirmationCode"=@ConfirmationCode, "FirebaseInfo"=@FirebaseInfo, "PaymentTerm"=@PaymentTerm, "ProfileImageFileDataId"=@ProfileImageFileDataId, "ProfileImageThumbnailFileDataId"=@ProfileImageThumbnailFileDataId, "FlightMarkupOverride"=@FlightMarkupOverride, "Gender"=@Gender, "PreferredDepartureAirportIataCode"=@PreferredDepartureAirportIataCode, "PassportNationalityCode"=@PassportNationalityCode, "PassportExpiryDate"=@PassportExpiryDate, "PassportNumber"=@PassportNumber, "NationalityCode"=@NationalityCode, "DateOfBirth"=@DateOfBirth, "CallingCode"=@CallingCode, "InvoicingDetails"=@InvoicingDetails, "MarketingConsent"=@MarketingConsent, "LoanApplicationTimeoutExpiry"=@LoanApplicationTimeoutExpiry, "LoginAttempt"=@LoginAttempt, "LockoutEnd"=@LockoutEnd, "Notes"=@Notes, "EnableTSO"=@EnableTSO WHERE "SystemUserId"=@SystemUserIdPARAMS: @SystemUserId=4815, @PassportExpiryDate=1/1/0001 12:00:00 AM, ...
This also does not work (but should not be necessary): DateOnly.FromDateTime(DateTime.MinValue)
.
Not exactly sure why this is happening. Does the date converter for DateOnly need to handle this for SQL Server differently?
ServiceStack.OrmLite.SqlServer.Data 5.13.2 on net6