Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Google.Cloud.EntityFrameworkCore.Spanner.Storage.Internal;

internal class SpannerDateDateTimeTypeMapping : SpannerDateTypeMapping
{
public SpannerDateDateTimeTypeMapping() : base(typeof(DateTime))
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ internal class SpannerDateTypeMapping : RelationalTypeMapping
v => SpannerDate.FromDateTime(v));

public SpannerDateTypeMapping()
: this(typeof(SpannerDate))
{ }

protected SpannerDateTypeMapping(System.Type clrType)
: base(new RelationalTypeMappingParameters(
new CoreTypeMappingParameters(typeof(SpannerDate), s_converter),
new CoreTypeMappingParameters(clrType,
// use converter only for SpannerDate; DateTime maps directly
clrType == typeof(SpannerDate) ? s_converter : null
),
"DATE", StoreTypePostfix.None, System.Data.DbType.Date))
{ }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private static readonly BoolTypeMapping s_bool
= new SpannerBoolTypeMapping(SpannerDbType.Bool.ToString());

private static readonly SpannerDateTypeMapping s_date = new SpannerDateTypeMapping();
private static readonly SpannerDateDateTimeTypeMapping s_dateTimeDate = new SpannerDateDateTimeTypeMapping();

private static readonly SpannerDateOnlyTypeMapping s_dateonly = new ();

Expand Down Expand Up @@ -327,6 +328,12 @@ private RelationalTypeMapping FindRawMapping(RelationalTypeMappingInfo mappingIn
if (_storeTypeMappings.TryGetValue(storeTypeName, out var mapping)
|| _storeTypeMappings.TryGetValue(storeTypeNameBase, out mapping))
{
// if DateTime is being used to map to DATE we need to use the default DateTime<>DateTime mapping instead of trying to use DateTime<>SpannerDate

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This comment is a bit misleading. The mapping being returned is for DateTime to the store type DATE, not a DateTime<>DateTime mapping. This logic is special handling for when a DateTime property is explicitly configured to map to a DATE column. A clearer comment would help future maintainers understand this specific logic.

// When mapping DateTime to DATE, use a specific mapping for DateTime. The default DATE mapping is for SpannerDate and uses a converter.

if (mapping == s_date && clrType == typeof(DateTime))
{
return s_dateTimeDate;
}

if (clrType == null
|| mapping.ClrType == clrType
|| mapping.Converter?.ProviderClrType == clrType)
Expand Down
Loading