问题
var sw = new Stopwatch();
sw.Start();
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<ImgSimContext>());
using (var db = new ImgSimContext())
{
SqlConnection.ClearAllPools();
db.Database.Initialize(force: true);
sw.Stop();
Console.WriteLine("Booted in {0}ms", sw.ElapsedMilliseconds);
This takes about 2 seconds, even when the database has already been created. Is there any way I can speed it up?
回答1:
If you are using EF6, then it is a known issue as described here: https://entityframework.codeplex.com/workitem/1749
来源:https://stackoverflow.com/questions/24222789/entity-framework-slow-to-connect-to-database