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

Support Microsoft.Data.SqlClient for Tanneryd.BulkOperations.EF6 #42

Open
zane-woodard-drc opened this issue Jun 10, 2024 · 7 comments
Open

Comments

@zane-woodard-drc
Copy link

zane-woodard-drc commented Jun 10, 2024

With the release of Entity Framework 6.5, the Microsoft.Data.SqlClient provider can be through the Microsoft.EntityFramework.SqlServer package. However, wrapping EF6.5 to use the better supported SQL provider makes it incompatible with the existing Tanneryd.BulkOperations.EF6.

After completing the migration described by the Microsoft.EntityFramework.SqlServer README, Tanneryd.BulkOperations.EF6 began throwing this exception:

Message: Unable to cast object of type 'Microsoft.Data.SqlClient.SqlConnection' to type 'System.Data.SqlClient.SqlConnection'.
TARGETSITE: System.Data.SqlClient.SqlConnection GetSqlConnection(System.Data.Entity.DbContext)
STACKTRACE:    at Tanneryd.BulkOperations.EF6.DbContextExtensions.GetSqlConnection(DbContext ctx)
   at Tanneryd.BulkOperations.EF6.DbContextExtensions.GetClusteredIndexColumns(DbContext ctx, String schema, String tableName, SqlTransaction sqlTransaction, Mappings mappings)
   at Tanneryd.BulkOperations.EF6.DbContextExtensions.BulkInsertAll[T](DbContext ctx, BulkInsertRequest`1 request)
   at Tanneryd.BulkOperations.EF6.DbContextExtensions.BulkInsertAll[T](DbContext ctx, IList`1 entities, SqlTransaction transaction, Boolean recursive)
@mtanneryd
Copy link
Owner

mtanneryd commented Jun 11, 2024 via email

@mtanneryd
Copy link
Owner

Hi!

I can see at https://learn.microsoft.com/en-us/ef/ef6/what-is-new/ that they claim to have been releasing EF 6.5.0 to nuget in June but I cannot find the actual nuget package at nuget.org. Have you installed a preview?

@zane-woodard-drc
Copy link
Author

Yea, full version id is 6.5.0-preview2-24180-01

The 6.5 release has been in a strange state for awhile, but docs are starting to be updated so I'd guess it's leaving preview soon.

@mtanneryd
Copy link
Owner

Version 2.1.0 is now using EF 6.5.1 and I tried running the tests in Tanneryd.BulkOperations.EF6.NET47.Tests using the new MicrosoftSqlDbConfiguration but everything seems to work just fine. Can you still reproduce the issue using 2.1.0?

@zane-woodard-drc
Copy link
Author

Yea, updated to EF 6.5.1 this morning and still seeing the issue. I see your recent commit to upgrade to EF 6.5.1, did you also switch to Microsoft.Data.SqlClient in the test project?

EF6.5 doesn't force a switch to Microsoft.Data.SqlClient, but support for Microsoft.Data.SqlClient is one of its biggest changes. Guide for switching with EF6.5 is here:
https://learn.microsoft.com/en-us/ef/ef6/what-is-new/microsoft-ef6-sqlserver

@mtanneryd
Copy link
Owner

I did force the switch in the test project actually and had no problems running the tests. The current version on github does not force the switch though.

When testing it I used the following attribute on the context class:
[DbConfigurationType(typeof(MicrosoftSqlDbConfiguration))]

@mtanneryd
Copy link
Owner

Hmm, I might have missed some additional required code changes. I’ll give it another try later. Watching France vs Portugal in the UEFA EURO 2024.

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

No branches or pull requests

2 participants