-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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 opting out of RETURNING/OUTPUT clauses in SaveChanges #29917
Conversation
src/EFCore.SqlServer/Extensions/SqlServerEntityTypeExtensions.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Metadata/Conventions/SqlServerOutputClauseConvention.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Metadata/Conventions/SqlServerOutputClauseConvention.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Update/Internal/SqlServerUpdateSqlGenerator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Extensions/SqlServerEntityTypeExtensions.cs
Outdated
Show resolved
Hide resolved
a3efd1a
to
8f95f80
Compare
@AndriySvyryd I've pushed some updates; this is still a draft to get some feedback though. Can you please confirm you're OK with the below? FWIW I think this really is complex for what we're doing here.
(any other review remarks welcome as well, of course). |
8f95f80
to
16216eb
Compare
I think that by not using the same granularity as triggers the convention logic is more complex than it needs to be.
It's generally messy to propagate configuration using conventions. A more robust approach would be to throw if this is configured on a non-root entity type and add |
Can we do that given that IsSqlOutputClauseUsed is SQL Server-specific and ITable is relational? If I understand things correctly, the creation of the Table (in RelationalModel) also doesn't allow for provider-specific customizations. Maybe we should have a quick call to discuss this. |
It does. You can add an annotation in |
@AndriySvyryd OK, I pushed a change... UseSqSqlOutputClause is now recorded (only) in a mapping fragment (I've removed the API to set/get it on entity type without a StoreObjectIdentifier). I ended up not using SqlServerAnnotationProvider, just having the IsSqlOutputClauseUsed extension accessor on ITable access the appropriate mapping fragments on all entity types mapped to that table. I agree this is simpler/better, and also supports better granularity. I wanted to get an OK on the approach before continuing. One last thing I'm not sure about:
Sounds good - but how do we handle a case where an entity type is made part of a TPH hierarchy after UseSqlOutputClause(false) is called on it (or after a trigger is added to it)? Is there a better solution than detecting that in the convention and moving setting to the root? And if we do this specific propagation, should we just support it when the setting is done on the non-root entity type after it's added to the hierarchy? |
37d00f4
to
84c2033
Compare
You still need to have the method on
I am saying that if that happens we should just throw and make the user configure it on the root themselves, so we don't need to propagate anything |
Thanks, I think I understand better how mapping fragments are supposed to work. I've pushed another commit handling the implicit/main mapping fragment and disallowing UseSqlOutputClause for non-root TPH entity types; hopefully this is OK. Take a look, if so I'll do the changes for SQLite (where I think we'd need a convention just to throw for the non-root TPH entity type thing). |
src/EFCore.SqlServer/Extensions/SqlServerEntityTypeExtensions.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Extensions/SqlServerEntityTypeExtensions.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Extensions/SqlServerEntityTypeMappingFragmentExtensions.cs
Outdated
Show resolved
Hide resolved
c1df479
to
1d0763c
Compare
Thanks @AndriySvyryd, I think this should be ready for a final review. |
src/EFCore.SqlServer/Infrastructure/Internal/SqlServerModelValidator.cs
Outdated
Show resolved
Hide resolved
test/EFCore.SqlServer.Tests/Infrastructure/SqlServerModelValidatorTest.cs
Show resolved
Hide resolved
test/EFCore.SqlServer.Tests/Infrastructure/SqlServerModelValidatorTest.cs
Outdated
Show resolved
Hide resolved
/// <param name="table">The table.</param> | ||
/// <returns><see langword="true" /> if the SQL OUTPUT clause is used to save changes to the table.</returns> | ||
public static bool IsSqlOutputClauseUsed(this ITable table) | ||
=> table.EntityTypeMappings.All(e => e.EntityType.IsSqlOutputClauseUsed(StoreObjectIdentifier.Table(table.Name, table.Schema))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider caching this and IsSqlReturningClauseUsed
in an annotation.
@AndriySvyryd fixed it all, if you want to take a final look. |
src/EFCore.SqlServer/Infrastructure/Internal/SqlServerModelValidator.cs
Outdated
Show resolved
Hide resolved
0f916e8
to
633dc0e
Compare
Hello @roji! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Apologies, while this PR appears ready to be merged, I've been configured to only merge when all checks have explicitly passed. The following integrations have not reported any progress on their checks and are blocking auto-merge:
These integrations are possibly never going to report a check, and unblocking auto-merge likely requires a human being to update my configuration to exempt these integrations from requiring a passing check. Give feedback on thisFrom the bot dev teamWe've tried to tune the bot such that it posts a comment like this only when auto-merge is blocked for exceptional, non-intuitive reasons. When the bot's auto-merge capability is properly configured, auto-merge should operate as you would intuitively expect and you should not see any spurious comments. Please reach out to us at fabricbotservices@microsoft.com to provide feedback if you believe you're seeing this comment appear spuriously. Please note that we usually are unable to update your bot configuration on your team's behalf, but we're happy to help you identify your bot admin. |
Fixes #29916