实体框架连接数据库的速度慢?

时间:2014-06-14 18:08:19

标签: c# sql-server entity-framework entity-framework-6.1

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);

即使已经创建了数据库,这也需要大约2秒钟。有什么办法可以加快速度吗?

1 个答案:

答案 0 :(得分:2)

如果您使用的是EF6,那么这是一个已知问题,如下所述: https://entityframework.codeplex.com/workitem/1749