Return default value for JetDateTimeTypeMapping derived classes as well. (#102)

pull/104/head
Laurents Meyer 5 years ago committed by GitHub
parent ad5799ffa6
commit db2c056b9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -771,18 +771,16 @@ namespace Microsoft.EntityFrameworkCore.Migrations
}
else if (defaultValue != null)
{
var typeMapping = columnType != null
? Dependencies.TypeMappingSource.FindMapping(defaultValue.GetType(), columnType)
: null;
if (typeMapping == null)
{
typeMapping = Dependencies.TypeMappingSource.GetMappingForValue(defaultValue);
}
defaultValue = defaultValue.GetType().IsTimeRelatedType()
? JetDateTimeTypeMapping.GenerateNonNullSqlLiteral(defaultValue, true, _options.EnableMillisecondsSupport)
var typeMapping = (columnType != null
? Dependencies.TypeMappingSource.FindMapping(defaultValue.GetType(), columnType)
: null) ??
Dependencies.TypeMappingSource.GetMappingForValue(defaultValue);
// All time related type mappings derive from JetDateTimeTypeMapping.
defaultValue = typeMapping is JetDateTimeTypeMapping dateTimeTypeMapping
? dateTimeTypeMapping.GenerateNonNullSqlLiteral(defaultValue, defaultClauseCompatible: true)
: typeMapping.GenerateSqlLiteral(defaultValue);
builder
.Append(" DEFAULT ")
.Append(defaultValue);

@ -45,10 +45,7 @@ namespace EntityFrameworkCore.Jet.Storage.Internal
base.ConfigureParameter(parameter);
}
protected override string GenerateNonNullSqlLiteral(object value)
=> base.GenerateNonNullSqlLiteral(
value is DateTimeOffset dateTimeOffset
? dateTimeOffset.UtcDateTime
: value);
protected override DateTime ConvertToDateTimeCompatibleValue(object value)
=> ((DateTimeOffset) value).UtcDateTime;
}
}

@ -53,17 +53,17 @@ namespace EntityFrameworkCore.Jet.Storage.Internal
}
protected override string GenerateNonNullSqlLiteral(object value)
=> GenerateNonNullSqlLiteral(value, false, _options.EnableMillisecondsSupport);
=> GenerateNonNullSqlLiteral(value, false);
public static string GenerateNonNullSqlLiteral(object value, bool defaultClauseCompatible, bool millisecondsSupportEnabled)
public virtual string GenerateNonNullSqlLiteral(object value, bool defaultClauseCompatible)
{
var dateTime = (DateTime) value;
var dateTime = ConvertToDateTimeCompatibleValue(value);
dateTime = CheckDateTimeValue(dateTime);
if (defaultClauseCompatible)
{
return _decimalTypeMapping.GenerateSqlLiteral(GetDateTimeDoubleValueAsDecimal(dateTime, millisecondsSupportEnabled));
return _decimalTypeMapping.GenerateSqlLiteral(GetDateTimeDoubleValueAsDecimal(dateTime, _options.EnableMillisecondsSupport));
}
var literal = new StringBuilder()
@ -77,7 +77,7 @@ namespace EntityFrameworkCore.Jet.Storage.Internal
literal.Append("#");
if (millisecondsSupportEnabled &&
if (_options.EnableMillisecondsSupport &&
time != TimeSpan.Zero)
{
// Round to milliseconds.
@ -97,6 +97,9 @@ namespace EntityFrameworkCore.Jet.Storage.Internal
return literal.ToString();
}
protected virtual DateTime ConvertToDateTimeCompatibleValue(object value)
=> (DateTime) value;
private static decimal GetDateTimeDoubleValueAsDecimal(DateTime dateTime, bool millisecondsSupportEnabled)
{
//

@ -28,7 +28,7 @@ namespace EntityFrameworkCore.Jet.Storage.Internal
protected override RelationalTypeMapping Clone(RelationalTypeMappingParameters parameters)
=> new JetTimeSpanTypeMapping(parameters, _options);
protected override string GenerateNonNullSqlLiteral(object value)
=> base.GenerateNonNullSqlLiteral(JetConfiguration.TimeSpanOffset + (TimeSpan) value);
protected override DateTime ConvertToDateTimeCompatibleValue(object value)
=> JetConfiguration.TimeSpanOffset + (TimeSpan) value;
}
}
Loading…
Cancel
Save