Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow value comparers for supertypes of the mapping's type #30939

Merged
1 commit merged into from
May 22, 2023
Merged
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
12 changes: 6 additions & 6 deletions src/EFCore/Storage/CoreTypeMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,28 +146,28 @@ protected CoreTypeMapping(CoreTypeMappingParameters parameters)
Check.DebugAssert(
parameters.Comparer == null
|| converter != null
|| parameters.Comparer.Type == clrType,
|| parameters.Comparer.Type.IsAssignableFrom(clrType),
$"Expected {clrType}, got {parameters.Comparer?.Type}");
if (parameters.Comparer?.Type == clrType)
if (parameters.Comparer?.Type.IsAssignableFrom(clrType) == true)
Copy link

Choose a reason for hiding this comment

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

I'm not familiar with the EFCore codebase, but could this be simplified from:

if (parameters.Comparer?.Type.IsAssignableFrom(clrType) == true)

to:

if (parameters.Comparer?.Type.IsAssignableFrom(clrType))

Copy link
Member

Choose a reason for hiding this comment

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

It could be null, so the options are

if (parameters.Comparer?.Type.IsAssignableFrom(clrType) == true)

and

if (parameters.Comparer?.Type.IsAssignableFrom(clrType) ?? false)

Copy link

@vslee vslee Jun 21, 2023

Choose a reason for hiding this comment

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

Good point. And I wouldn't have ever have thought of your second option.

{
_comparer = parameters.Comparer;
}

Check.DebugAssert(
parameters.KeyComparer == null
|| converter != null
|| parameters.KeyComparer.Type == parameters.ClrType,
|| parameters.KeyComparer.Type.IsAssignableFrom(parameters.ClrType),
$"Expected {parameters.ClrType}, got {parameters.KeyComparer?.Type}");
if (parameters.KeyComparer?.Type == clrType)
if (parameters.KeyComparer?.Type.IsAssignableFrom(clrType) == true)
{
_keyComparer = parameters.KeyComparer;
}

Check.DebugAssert(
parameters.ProviderValueComparer == null
|| parameters.ProviderValueComparer.Type == (converter?.ProviderClrType ?? clrType),
|| parameters.ProviderValueComparer.Type.IsAssignableFrom(converter?.ProviderClrType ?? clrType),
$"Expected {converter?.ProviderClrType ?? clrType}, got {parameters.ProviderValueComparer?.Type}");
if (parameters.ProviderValueComparer?.Type == (converter?.ProviderClrType ?? clrType))
if (parameters.ProviderValueComparer?.Type.IsAssignableFrom(converter?.ProviderClrType ?? clrType) == true)
{
_providerValueComparer = parameters.ProviderValueComparer;
}
Expand Down
Loading