Hibernating Rhinos

Zero friction databases

Adding support for EntityFramework.BulkInsert in EFProf

We got a support request from one of our Entity Framework Profiler users which started to use a tool called EntityFramework.BulkInsert and it turns out that the appender of the profiler will throw the following exception when using the bulk insert:

EntityFramework.BulkInsert.Exceptions.BulkInsertProviderNotFoundException : 
BulkInsertProvider not found for 'HibernatingRhinos.Profiler.Appender.ProfiledDataAccess.ProfiledConnection`1[[System.Data.SqlClient.SqlClientFactory, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].
So we asked the user to send us a sample app that reproduce the issue, and once we got this rpero app it was easy so find the solution for this.
The user need to add the following lines in the beginning of the application:
ProviderFactory.Register<ProfiledEfSqlBulkInsertProviderWithMappedDataReader>("HibernatingRhinos.Profiler.Appender.ProfiledDataAccess.ProfiledConnection`1[[System.Data.SqlClient.SqlClientFactory, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]");

public class ProfiledEfSqlBulkInsertProviderWithMappedDataReader : EfSqlBulkInsertProviderWithMappedDataReader

{

   protected override string ConnectionString

   {

       get { return DbConnection.ConnectionString; }

   }

}

What is does basically is registering the ProfiledConnection, which is a wrapper against your DbConnection, in this case it is SqlConnection, 
with the IEfBulkInsertProvider instance that your application is using, which in this case it is EfSqlBulkInsertProviderWithMappedDataReader.
In this case we need to also override the EfSqlBulkInsertProviderWithMappedDataReader as it search for a field that is called _connectionString which the ProfiledConnection does not have.
It should have used the ConnectionString property, but now worries, we override the connection string and fixing this.

Posted By: Fitzchak Yitzchaki

Published at

Originally posted at

Comments

No comments posted yet.

Comments have been closed on this topic.