How can I implement DbContext Connection String in .NET Core?

后端 未结 5 991
生来不讨喜
生来不讨喜 2020-12-25 12:14

My situation is quite similar to this link or at least my code is similar and I am trying to find a way to apply this same method in .NET Core syntax.

Pass connectio

5条回答
  •  一向
    一向 (楼主)
    2020-12-25 13:01

    Another option would be to call the base constructor that takes a DbContextOptions:

    public BooksContext(string connectionString) : base(GetOptions(connectionString))
    {
    }
    
    private static DbContextOptions GetOptions(string connectionString)
    {
        return SqlServerDbContextOptionsExtensions.UseSqlServer(new DbContextOptionsBuilder(), connectionString).Options;
    }
    

提交回复
热议问题