目前我有这个
Public Class ApplicationDbContext
Inherits IdentityDbContext(Of ApplicationUser)
Public Sub New()
MyBase.New("DefaultConnection", throwIfV1Schema:=False)
End Sub
Public Shared Function Create() As ApplicationDbContext
Return New ApplicationDbContext()
End Function
如何使用这样的方法连接到另一个连接字符串?
答案 0 :(得分:1)
您可以向ApplicationDbContext
添加新构造函数,并将connectionstring
传递给IdentityDbContext
类。 IdentityDbContext
构造函数采用Name或ConnectionString,因此您可以通过构造函数传递其他连接字符串。有关详细信息,请参阅msdn
Imports System.Collections
Imports System.Collections.Generic
Imports System.Data
Imports System.Diagnostics
Public Class ApplicationDbContext
Inherits IdentityDbContext(Of ApplicationUser)
Public Sub New()
MyBase.New("DefaultConnection", throwIfV1Schema := False)
End Sub
Public Sub New(connectionstring As String)
MyBase.New("connectionstring")
End Sub
Public Shared Function Create() As ApplicationDbContext
Return New ApplicationDbContext()
End Function
End Class