DbContext 构造函数 (String, DbCompiledModel)
[本页针对的是实体框架版本 6。最新版本以“实体框架”NuGet 包的形式提供。有关实体框架的更多信息,请参见 msdn.com/data/ef。]
可以将给定字符串用作将连接到的数据库的名称或连接字符串来构造一个新的上下文实例,并从给定模型初始化该实例。 请参见有关这如何用于创建连接的类备注。
命名空间: System.Data.Entity
程序集: EntityFramework(在 EntityFramework.dll 中)
语法
声明
<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")> _
<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")> _
Public Sub New ( _
nameOrConnectionString As String, _
model As DbCompiledModel _
)
用法
Dim nameOrConnectionString As String
Dim model As DbCompiledModel
Dim instance As New DbContext(nameOrConnectionString, _
model)
[SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
[SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public DbContext(
string nameOrConnectionString,
DbCompiledModel model
)
[SuppressMessageAttribute(L"Microsoft.Usage", L"CA2214:DoNotCallOverridableMethodsInConstructors")]
[SuppressMessageAttribute(L"Microsoft.Reliability", L"CA2000:Dispose objects before losing scope")]
public:
DbContext(
String^ nameOrConnectionString,
DbCompiledModel^ model
)
[<SuppressMessageAttribute("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")>]
[<SuppressMessageAttribute("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")>]
new :
nameOrConnectionString:string *
model:DbCompiledModel -> DbContext
public function DbContext(
nameOrConnectionString : String,
model : DbCompiledModel
)
参数
- nameOrConnectionString
类型:System.String
数据库名称或连接字符串。
- model
类型:System.Data.Entity.Infrastructure.DbCompiledModel
支持此上下文的模型。