dotnet ef migrations {name} dotnet ef database update

时间:2016-10-13 23:10:14

标签: c# entity-framework-core

我今天首先学习实体框架核心和代码,通过关注多个网站上的视频来创建我自己的dbcontext。 我的项目确实创建了一个数据库,但它没有在SQL Server中执行。当我创建一个上下文实例并查看时,它表示数据库外观,所以我假设它在内存中。 我在哪里可以更改标志,或者在点网核的数千行样板中设置一个数字,以使其在sql server中创建数据库,而不是在内存中?

我使用命令行尝试创建它 dotnet ef migrations {name} dotnet ef database update

1 个答案:

答案 0 :(得分:0)

您可以告诉DbContext与dbContext中的SQL Server(或任何提供程序)一起使用。您可以通过两种方式执行此操作:

  1. 使用依赖注入
  2. 通过覆盖OnConfiguring方法     (在Context类中覆盖)
  3. 这是覆盖OnConfiguring方法

    的示例
    protected override void OnConfiguring(DbContextOptionsBuilder optionbuilder)
    {
        string connectionString = @"Server=localhost;Database=YourDataBaseName;Trusted_Connection=true;"
        optionbuilder.UseSqlServer(connectionString);
    }
    

    一定要退房 https://docs.efproject.net/en/latest/miscellaneous/configuring-dbcontext.htmlhttps://docs.efproject.net/en/latest/providers/sql-server/index.html了解更多信息

相关问题