-
Notifications
You must be signed in to change notification settings - Fork 332
Feature | Add SqlBulkCopyOptions.CacheMetadata flag #3939
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
Merged
samsharma2700
merged 19 commits into
main
from
dev/samsharma2700/sqlbulkcopy_metadata_optimization
Feb 26, 2026
Merged
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7110977
Add SqlBulkCopyOptions.CacheMetadata flag
samsharma2700 a3075fb
Fix references
samsharma2700 638a2ab
Feedback Changes
samsharma2700 855e63c
Merge branch 'main' of https://github.com/dotnet/SqlClient into dev/s…
samsharma2700 343ecd0
Handle column-pruning for cached data
samsharma2700 b7feea4
Merge branch 'main' of https://github.com/dotnet/SqlClient into dev/s…
samsharma2700 98a3f90
Retain per-column encryption fields
samsharma2700 832c073
Feedback changes
samsharma2700 198d2e9
Merge branch 'main' of https://github.com/dotnet/SqlClient into dev/s…
samsharma2700 4b1aef7
Nullify operationMetaData
samsharma2700 1b7dc5a
Simplify caching
samsharma2700 358714a
Merge branch 'main' into dev/samsharma2700/sqlbulkcopy_metadata_optim…
samsharma2700 7674146
Rename Optional Flag
samsharma2700 c06db4c
Fix _operationMetaData
samsharma2700 55c2ed9
Remove redundant check
samsharma2700 261761a
Update docs
samsharma2700 a4bf542
Update CachedMetadata property
samsharma2700 2663cf2
Add async tests
samsharma2700 58cf942
Improve readability
samsharma2700 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlBulkCopyCacheMetadataTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Data.SqlClient.Tests | ||
| { | ||
| public class SqlBulkCopyCacheMetadataTest | ||
| { | ||
| [Fact] | ||
| public void CacheMetadata_FlagValue_IsCorrect() | ||
| { | ||
| Assert.Equal(1 << 7, (int)SqlBulkCopyOptions.CacheMetadata); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CacheMetadata_CanBeCombinedWithOtherOptions() | ||
| { | ||
| SqlBulkCopyOptions combined = | ||
| SqlBulkCopyOptions.CacheMetadata | | ||
| SqlBulkCopyOptions.KeepIdentity | | ||
| SqlBulkCopyOptions.TableLock; | ||
|
|
||
| Assert.True((combined & SqlBulkCopyOptions.CacheMetadata) == SqlBulkCopyOptions.CacheMetadata); | ||
| Assert.True((combined & SqlBulkCopyOptions.KeepIdentity) == SqlBulkCopyOptions.KeepIdentity); | ||
| Assert.True((combined & SqlBulkCopyOptions.TableLock) == SqlBulkCopyOptions.TableLock); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CacheMetadata_DoesNotOverlapExistingFlags() | ||
|
samsharma2700 marked this conversation as resolved.
Outdated
|
||
| { | ||
| int cacheMetadataValue = (int)SqlBulkCopyOptions.CacheMetadata; | ||
| Assert.NotEqual((int)SqlBulkCopyOptions.Default, cacheMetadataValue); | ||
| Assert.NotEqual((int)SqlBulkCopyOptions.KeepIdentity, cacheMetadataValue); | ||
| Assert.NotEqual((int)SqlBulkCopyOptions.CheckConstraints, cacheMetadataValue); | ||
| Assert.NotEqual((int)SqlBulkCopyOptions.TableLock, cacheMetadataValue); | ||
| Assert.NotEqual((int)SqlBulkCopyOptions.KeepNulls, cacheMetadataValue); | ||
| Assert.NotEqual((int)SqlBulkCopyOptions.FireTriggers, cacheMetadataValue); | ||
| Assert.NotEqual((int)SqlBulkCopyOptions.UseInternalTransaction, cacheMetadataValue); | ||
| Assert.NotEqual((int)SqlBulkCopyOptions.AllowEncryptedValueModifications, cacheMetadataValue); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InvalidateMetadataCache_CanBeCalledWithoutError() | ||
| { | ||
| using SqlBulkCopy bulkCopy = new(new SqlConnection()); | ||
| bulkCopy.InvalidateMetadataCache(); | ||
|
samsharma2700 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| [Fact] | ||
| public void InvalidateMetadataCache_CanBeCalledMultipleTimes() | ||
| { | ||
| using SqlBulkCopy bulkCopy = new(new SqlConnection()); | ||
| bulkCopy.InvalidateMetadataCache(); | ||
| bulkCopy.InvalidateMetadataCache(); | ||
| bulkCopy.InvalidateMetadataCache(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InvalidateMetadataCache_WithCacheMetadataOption() | ||
| { | ||
| using SqlBulkCopy bulkCopy = new(new SqlConnection(), SqlBulkCopyOptions.CacheMetadata, null); | ||
| bulkCopy.InvalidateMetadataCache(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void InvalidateMetadataCache_WithoutCacheMetadataOption() | ||
| { | ||
| using SqlBulkCopy bulkCopy = new(new SqlConnection(), SqlBulkCopyOptions.Default, null); | ||
| bulkCopy.InvalidateMetadataCache(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DestinationTableName_Change_DoesNotThrowWithCacheMetadata() | ||
| { | ||
| using SqlBulkCopy bulkCopy = new(new SqlConnection(), SqlBulkCopyOptions.CacheMetadata, null); | ||
| bulkCopy.DestinationTableName = "Table1"; | ||
| bulkCopy.DestinationTableName = "Table2"; | ||
| bulkCopy.DestinationTableName = "Table1"; | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Constructor_WithCacheMetadataOption_Succeeds() | ||
| { | ||
| using SqlBulkCopy bulkCopy = new(new SqlConnection(), SqlBulkCopyOptions.CacheMetadata, null); | ||
| Assert.NotNull(bulkCopy); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Constructor_WithCacheMetadataAndConnectionString_Succeeds() | ||
| { | ||
| using SqlBulkCopy bulkCopy = new("Server=localhost", SqlBulkCopyOptions.CacheMetadata); | ||
| Assert.NotNull(bulkCopy); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.