Skip to content

Fix range mapping - #698

Merged
roji merged 3 commits into
npgsql:devfrom
roji:fix-range-mapping
Nov 15, 2018
Merged

Fix range mapping#698
roji merged 3 commits into
npgsql:devfrom
roji:fix-range-mapping

Conversation

@roji

@rojiroji commented Nov 14, 2018

Copy link
Copy Markdown
Member

Fixes#688

Note the rename from RangeMappingInfo to UserRangeDefinition... While working on this it got confusing, as RangeMappingInfo wasn't a MappingInfo in the strict EF Core sense. I've left the public-facing MapRange() method on NpgsqlDbContextOptionsBuilder, partially to avoid breaking existing code, and partially because it seems acceptable to call this "mapping" in user-facing APIs, while internally it produces a "definition".

We used to eagerly create mappings for user-defined ranges in the
constructor of NpgsqlTypeMappingSource. This was too early, and did not
have access to mappings coming from plugins, so creating a user-defined
range over NodaTime types failed.
We know create mappings for user-defined ranges late, when FindMapping()
is called.
Fixesnpgsql#688
It was neither a MappingInfo nor a mapping in the narrow EF Core sense.

@austindrenskiaustindrenski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The implementation here looks good.

Would it make sense to add a test case for the pattern in #688 that triggered this?

@austindrenski

austindrenski commented Nov 14, 2018

Copy link
Copy Markdown
Contributor

I've left the public-facing MapRange() method on NpgsqlDbContextOptionsBuilder, partially to avoid breaking existing code, and partially because it seems acceptable to call this "mapping" in user-facing APIs, while internally it produces a "definition".

Would it make sense to deprecate[Obsolete] it for 2.2 and introduce one with the new terminology?

@roji

roji commented Nov 14, 2018

Copy link
Copy Markdown
MemberAuthor

Would it make sense to add a test case for the pattern in #688 that triggered this?

It does :) We haven't yet written any tests on NpgsqlTypeMappingSource, but now's a good a time as ever to start... I'll add some testing tomorrow.

Would it make sense to [Obsolete] it for 2.2 and introduce one with the new terminology?

I'm not sure... From the user perspective they really are mapping a PostgreSQL range type (the first parameter) to a CLR subtype (the second parameter). The only issue is that this isn't a mapping in the internal EF Core sense: it does not extend TypeMapping and isn't a TypeMappingInfo either. So it may be OK to leave MapRange() for the user-facing API. Let me know what you think - I'm not 100% sure about this.

@austindrenski

Copy link
Copy Markdown
Contributor

Would it make sense to add a test case for the pattern in #688 that triggered this?

It does :) We haven't yet written any tests on NpgsqlTypeMappingSource, but now's a good a time as ever to start... I'll add some testing tomorrow.

Sounds great!

Would it make sense to [Obsolete] it for 2.2 and introduce one with the new terminology?

I'm not sure... From the user perspective they really are mapping a PostgreSQL range type (the first parameter) to a CLR subtype (the second parameter). The only issue is that this isn't a mapping in the internal EF Core sense: it does not extend TypeMapping and isn't a TypeMappingInfo either. So it may be OK to leave MapRange() for the user-facing API. Let me know what you think - I'm not 100% sure about this.

OK—keeping it as is sounds fine then. No need to churn the public API if we're really just talking about implementation details at this point.

@roji

roji commented Nov 15, 2018

Copy link
Copy Markdown
MemberAuthor

@austindrenski I pushed some tests, please take a look.

@austindrenskiaustindrenski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks great. One tiny nit to fix if you have time, otherwise merge at will.

public void By_StoreType_with_wrong_ClrType(string storeType, Type wrongClrType)
=> Assert.Null(Source.FindMapping(wrongClrType, storeType));

class UnknownType {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Could you move this down alongside DummyType?

@roji
roji merged commit ecf8408 into npgsql:devNov 15, 2018
@roji

roji commented Nov 15, 2018

Copy link
Copy Markdown
MemberAuthor

Fixed nit and merged, thanks for the reviewing!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@roji@austindrenski