I'm trying to increase the performance for insert operations by using EntityFramework.BulkInsert
.
Currently I have something like this:
var theEntities = ChangeTracker.Entries<BaseEntity>().ToList();
this.BulkInsert(theEntities, _transaction.UnderlyingTransaction);
Which throws an exception:
No table mappings provided
I don't see the point or what I can do as of examples for EF6, database-first are really hard to find.
Any ideas?
Changing the code as from the comments, it now throws the following exception:
Type 'Private_DatabaseEntities.BaseEntity' is not found in context 'Private_DatabaseEntities.EntityModelContext'
whereas EntityModelContext
is the context I'm using (inheriting from DbContext
) and BaseEntity
is the base-class for all concrete entities.
You try to insert the DbEntityEntry which is not mapped and not the current entity.
Try this
var theEntities = ctx.ChangeTracker.Entries<BaseEntity>().Select(x => x.Entity).ToList();
this.BulkInsert(theEntities, _transaction.UnderlyingTransaction);
EntityFramework.BulkInsert library work only with simple entity. It's doesn't work with inheritance such as TPC and TPT and doesn't return identity value.
To fix your second issue, you will have to use another library.
Entity Framework Extensions
Allow to BulkSaveChanges, BulkInsert, BulkUpdate, BulkDelete and BulkMerge entities to your database. Support all kinds of associations and inheritances (TPC, TPH and TPT)
// Easy to use
context.BulkSaveChanges();
// Easy to customize
context.BulkSaveChanges(operation => operation.BatchSize = 1000);
// For direct bulk insert
var theEntities = ctx.ChangeTracker.Entries<BaseEntity>().Select(x => x.Entity).ToList();
context.BulkInsert(theEntities);
Disclaimer: I'm the owner of the project Entity Framework Extensions