如何设置实体框架的核心迁移超时? [英] How to set Entity Framework Core migration timeout?

查看:301
本文介绍了如何设置实体框架的核心迁移超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用EF核心的最新版本(1.0.0)版本。我有一个迁移到一个相当大的数据库上运行。

I'm using the latest (1.0.0) version of EF Core. I have a migration to run on a quite big database.

我运行:

DOTNET EF数据库更新-c ApplicationDbContext

dotnet ef database update -c ApplicationDbContext

和获取:

超时过期。之前的
操作或服务器完成的超时时间已过不响应。

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

在连接字符串我明确设置超时时间,像这样:

In the connection string I explicitly set the timeout like so:

连接超时= 150000

Connect Timeout=150000

不幸的是,它并没有帮助。我应该怎么做呢?

Unfortunately, it didn't help. How should I do this?

推荐答案

您收到错误消息是一个命令超时,没有连接超时。有没有办法使用EF命令时设置的CommandTimeout 上的上下文。但是你可以在构造函数中全局设置,然后以后删除它,如果你不需要保持它:

The error message you are getting is for a Command timeout, not a connection timeout. There is no way to set the CommandTimeout on a context when using EF commands. But you can set it globally in the constructor, and then remove it later if you don't need to keep it:

public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext()
    {
        Database.SetCommandTimeout(150000);
    }
}

这篇关于如何设置实体框架的核心迁移超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆