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

Enable nullable backing field pattern for store-generated defaults #15820

Closed
wants to merge 1 commit into from

Conversation

ajcvickers
Copy link
Contributor

Fixes #15182

There is quite a fundamental change included here: the CLR type reported for a mapped property is now the backing field type, if it is known, not the property type. This is what allows a three states to be saved for a non-nullable property with a nullable backing field.

Perceptive readers will realize that this means that the CLR type of an IProperty can now change if the backing field is changed.

The most difficult case to handle seems to be properties backed by object fields. This likely isn't very common, but we had tests for it because of previous issues reported. One scenario is not working here--creating a shadow property FK by convention for a PK that is backed by an object field. I will file a bug for this.

Query changes are just what I needed to do to re-enable some tests to get coverage for this change. In particular, the type inference is not a universal solution, but unblocks important tests.

Fixes #15182

There is quite a fundamental change included here: the CLR type reported for a mapped property is now the backing field type, if it is known, not the property type. This is what allows a three states to be saved for a non-nullable property with a nullable backing field.

Perceptive readers will realize that this means that the CLR type of an `IProperty` can now change if the backing field is changed.

The most difficult case to handle seems to be properties backed by `object` fields. This likely isn't very common, but we had tests for it because of previous issues reported. One scenario is not working here--creating a shadow property FK by convention for a PK that is backed by an object field. I will file a bug for this.

Query changes are just what I needed to do to re-enable some tests to get coverage for this change. In particular, the type inference is not a universal solution, but unblocks important tests.
@ajcvickers ajcvickers requested review from smitpatel, AndriySvyryd and roji and removed request for smitpatel and AndriySvyryd May 27, 2019 17:26
// literals in the expression tree. It adds a new converter onto the type mapper
// that takes the literal and converts it back to the type that the type mapping
// is expecting.
// This code is temporary until more complete type inference is completed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you point me to the test which is failing so I can understand the type of tree encountered?

If this is dependent on a service then we can move the method to SqlExpressionFactory rather than extension method. Everyone using this method now having to take service looks ugly when they have already one service available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the type mapping tests--see my comment. Keep in mind that this is just to unblock tests. I fully expect it to change in the future when we have working type inference.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's go ahead with this then.

@@ -203,7 +204,7 @@ public virtual void Can_perform_query_with_ansi_strings_test()
}
}

[Fact(Skip = "QueryIssue")]
[Fact]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@smitpatel: All these Can_query... tests

@@ -1148,13 +1222,12 @@ protected class WithBackingFields
{
private int _id;

#pragma warning disable RCS1085 // Use auto-implemented property.
// ReSharper disable once ConvertToAutoProperty
Copy link
Contributor

Choose a reason for hiding this comment

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

Moving VS pragma to Resharper disable?

Copy link
Contributor

@smitpatel smitpatel left a comment

Choose a reason for hiding this comment

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

Query change looks fine.

Copy link
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

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

If we want to enable flexible O-C mapping in the future we should encapsulate O-space concerns better.

When a backing field is set for a property its conceptual type doesn't change. Store type mapping should only use the conceptual type.

Consumers that need the O-space type should get the appropriate one depending on the PropertyAccessMode that's currently set.

ajcvickers added a commit that referenced this pull request Jun 6, 2019
PR #15820 will be closed since Andriy suggested a potentially better way to add the feature.

However, I wanted to get the additional test coverage checked in now, with the three tests that explicitly test the new functionality skipped for now.
@ajcvickers
Copy link
Contributor Author

Closing this since @AndriySvyryd suggested a different approach that is potentially less impactful and cleaner.

@ajcvickers ajcvickers closed this Jun 6, 2019
ajcvickers added a commit that referenced this pull request Jun 6, 2019
PR #15820 will be closed since Andriy suggested a potentially better way to add the feature.

However, I wanted to get the additional test coverage checked in now, with the three tests that explicitly test the new functionality skipped for now.
@smitpatel smitpatel deleted the SillyMidOff0523 branch June 11, 2019 23:42
Sign up for free to 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.

Enable nullable backing field pattern for store-generated defaults
3 participants