How does Entity Framework convert an EntityTransaction into a provider specific transaction?
I've got an Entity Framework 4 data mode. I'm loading data into a database using stored procedures since EF is so slow. We use the entity model to call the stored procedures. Everything has to be in one transaction.
In order to speed up the process, I need to perform some bulk copy operations. I'm using SQL Anywhere and their ADO.NET provider software for this.
When I call context.Connection.BeginTransactin(), I get an EntityTransaction back. Actually, my variable is a DbTransaction, which is the base class for all transactions. But the actual object returned is an EntityTransaction.
I can't cast an EntityTransaction into the provider specific transaction class (SAConnection in this case). If I do, I get a cast exception. Yet, somehow, when the entity context calls the stored procedures, it's enlisting the provider specific command objects it creates into the transaction represented by that EntityTransaction object.
How does the provider do this? Is it a mechanism I can use to get a provider-specific transaction object for my bulk copy operations?
I have taken a look at the EntityTransaction class and in fact an internal property called StoreTransaction exists. If found some source-code in this SO discussion: This SqlTransaction has completed; it is no longer usable. Entity Framework Code First which might help you out.
Keep in mind, that this won't work in partial trust environments, which do not allow you to access members using reflection.