Sunday, 18 August 2013

How to Prevent EF5 LocalDB Connection From Closing

How to Prevent EF5 LocalDB Connection From Closing

I've built an applciation using EF5 and CodeFirst. At runtime my
application creates a LocalDB databse file and a class-level instance of a
DataContext. Everything works fine however inserts are slow after about
50,000 records (approx 20MB MDF file). In debug I can see the internal
Connection's state is set to 'Closed'. I assume EF5 is closing the
connection after each insert and then re-opening it when needed.
How can I prevent Entity Framework from closing the connection? This is a
local that will potentially need to import up to 500k records in the
shortest period of time.

No comments:

Post a Comment