EF.BulkInsert and Glimpse - don't mix well

I have an EF6 / ASP.NET 4.5 Webforms solution, and now I need to add some functionality to allow bulk inserts from Excel files.

I know that EF out of the box is not optimized for bulk operations, so I looked around and found "EF BulkInsert" ( https://efbulkinsert.codeplex.com/ ) to facilitate this.

I tried this in a test application, and it worked wonderfully, but when I included it in the main application, it broke. When you try to make an actual bulk insert call, the system crashes with the exception:

BulkInsertProviderNotFoundException: BulkInsertProvider not found for 'Glimpse.Ado.AlternateType.GlimpseDbConnection. To register a new provider, use EntityFramework.BulkInsert.ProviderFactory.Register () method '

Now I'm not sure that this is the fault of Glimpse or EF BulkInsert (or both), and, unfortunately, I can not find any solution - none of the developers of these programs provides any insights or workarounds ....

Has anyone here stumbled upon the same problem and found a solution for it?

+4
source share
1 answer

- , Glimpse DbConnection EF BulkInsert "_connectionString", . EF BulkInsert , - , Glimpse .

, , EfSqlBulkInsertProviderWithMappedDataReader ( ):

    public class GlimpseProvider : EfSqlBulkInsertProviderWithMappedDataReader, IEfBulkInsertProvider
    {

        private static object GetPrivateFieldValue(object obj, string propName) {
            if (obj == null) throw new ArgumentNullException("obj");
            Type t = obj.GetType();
            FieldInfo fieldInfo = null;
            PropertyInfo propertyInfo = null;
            while (fieldInfo == null && propertyInfo == null && t != null) {
                fieldInfo = t.GetField(propName,
                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                if (fieldInfo == null) {
                    propertyInfo = t.GetProperty(propName,
                        BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                }

                t = t.BaseType;
            }
            if (fieldInfo == null && propertyInfo == null)
                throw new ArgumentOutOfRangeException("propName",
                    string.Format("Field {0} was not found in Type {1}", propName, obj.GetType().FullName));

            if (fieldInfo != null)
                return fieldInfo.GetValue(obj);

            return propertyInfo.GetValue(obj, null);
        }

        protected override IDbConnection DbConnection {
            get { return (IDbConnection)GetPrivateFieldValue(this.Context.Database.Connection, "InnerConnection"); }
        }
    }

. OnModelCreating.

EntityFramework.BulkInsert.ProviderFactory.Register<GlimpseProvider>("Glimpse.Ado.AlternateType.GlimpseDbConnection");

, EF BulkInsert.

+6

All Articles