mtanneryd / ef-bulk-operations

Bulk operations for Entity Framework 6
Apache License 2.0
80 stars 30 forks source link

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

Open zane-woodard-drc opened 5 months ago

zane-woodard-drc commented 5 months ago

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 commented 5 months ago

Thanks for the feedback. I will look into this as soon as I can.Måns TånnerydTånneryd IT ABBarrskogsvägen 1918653 Vallentuna+46-705140093https://se.linkedin.com/in/manstanneryd10 juni 2024 kl. 23:55 skrev zane-woodard-drc @.***>: 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, BulkInsertRequest1 request) at Tanneryd.BulkOperations.EF6.DbContextExtensions.BulkInsertAll[T](DbContext ctx, IList1 entities, SqlTransaction transaction, Boolean recursive)

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

mtanneryd commented 5 months ago

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 commented 5 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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.