DataContext Construtores
Definição
Inicializa uma nova instância da classe DataContext.Initializes a new instance of the DataContext class. A cadeia de conexão que você usa pode ser uma cadeia de conexão ADO.NET.The connection string you use can be an ADO.NET connection string. Você também pode especificar um nome de arquivo para um arquivo SQL Server Express ou SQL Server Compact.You can also specify a filename to a SQL Server Express or SQL Server Compact file.
Sobrecargas
| DataContext(IDbConnection) |
Inicializa uma nova instância da DataContext classe referenciando a conexão usada pelo .NET Framework.Initializes a new instance of the DataContext class by referencing the connection used by the .NET Framework. |
| DataContext(IDbConnection, MappingSource) |
Inicializa uma nova instância da classe DataContext referenciando uma conexão e uma fonte de mapeamento.Initializes a new instance of the DataContext class by referencing a connection and a mapping source. |
| DataContext(String, MappingSource) |
Inicializa uma nova instância da classe DataContext referenciando uma fonte de arquivo e fonte de mapeamento.Initializes a new instance of the DataContext class by referencing a file source and a mapping source. |
| DataContext(String) |
Inicializa uma nova instância da classe DataContext referenciando uma fonte de arquivo.Initializes a new instance of the DataContext class by referencing a file source. |
DataContext(IDbConnection)
Inicializa uma nova instância da DataContext classe referenciando a conexão usada pelo .NET Framework.Initializes a new instance of the DataContext class by referencing the connection used by the .NET Framework.
public:
DataContext(System::Data::IDbConnection ^ connection);
public DataContext (System.Data.IDbConnection connection);
new System.Data.Linq.DataContext : System.Data.IDbConnection -> System.Data.Linq.DataContext
Public Sub New (connection As IDbConnection)
Parâmetros
- connection
- IDbConnection
A conexão usada pelo .NET Framework.The connection used by the .NET Framework.
Comentários
Um DataContext abre e fecha uma conexão de banco de dados conforme necessário se você fornecer uma conexão fechada ou uma cadeia de conexão.A DataContext opens and closes a database connection as needed if you provide a closed connection or a connection string. Em geral, você nunca precisará chamar Dispose em um DataContext .In general, you should never have to call Dispose on a DataContext. Se você fornecer uma conexão aberta, o DataContext não irá fechá-la.If you provide an open connection, the DataContext will not close it. Portanto, não crie uma instância de DataContext com uma conexão aberta, a menos que você tenha um bom motivo para fazer isso.Therefore, do not instantiate a DataContext with an open connection unless you have a good reason to do this. Em uma System.Transactions transação, um DataContext não abrirá ou fechará uma conexão para evitar a promoção.In a System.Transactions transaction, a DataContext will not open or close a connection to avoid promotion.
Aplica-se a
DataContext(IDbConnection, MappingSource)
Inicializa uma nova instância da classe DataContext referenciando uma conexão e uma fonte de mapeamento.Initializes a new instance of the DataContext class by referencing a connection and a mapping source.
public:
DataContext(System::Data::IDbConnection ^ connection, System::Data::Linq::Mapping::MappingSource ^ mapping);
public DataContext (System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mapping);
new System.Data.Linq.DataContext : System.Data.IDbConnection * System.Data.Linq.Mapping.MappingSource -> System.Data.Linq.DataContext
Public Sub New (connection As IDbConnection, mapping As MappingSource)
Parâmetros
- connection
- IDbConnection
A conexão usada pelo .NET Framework.The connection used by the .NET Framework.
- mapping
- MappingSource
Uma fonte de mapeamento.A source for mapping.
Aplica-se a
DataContext(String, MappingSource)
Inicializa uma nova instância da classe DataContext referenciando uma fonte de arquivo e fonte de mapeamento.Initializes a new instance of the DataContext class by referencing a file source and a mapping source.
public:
DataContext(System::String ^ fileOrServerOrConnection, System::Data::Linq::Mapping::MappingSource ^ mapping);
public DataContext (string fileOrServerOrConnection, System.Data.Linq.Mapping.MappingSource mapping);
new System.Data.Linq.DataContext : string * System.Data.Linq.Mapping.MappingSource -> System.Data.Linq.DataContext
Public Sub New (fileOrServerOrConnection As String, mapping As MappingSource)
Parâmetros
- fileOrServerOrConnection
- String
Esse argumento pode ser um dos seguintes:This argument can be any one of the following:
O nome de um arquivo em que reside um banco de dados SQL Server Express.The name of a file where a SQL Server Express database resides.
O nome de um servidor em que existe um banco de dados.The name of a server where a database is present. Nesse caso, o provedor usa o banco de dados padrão de um usuário.In this case the provider uses the default database for a user.
Uma cadeia de conexão completa.A complete connection string. O LINQ to SQL passa apenas a cadeia de caracteres para o provedor sem modificação.LINQ to SQL just passes the string to the provider without modification.
- mapping
- MappingSource
Uma fonte de mapeamento.A source for mapping.
Aplica-se a
DataContext(String)
Inicializa uma nova instância da classe DataContext referenciando uma fonte de arquivo.Initializes a new instance of the DataContext class by referencing a file source.
public:
DataContext(System::String ^ fileOrServerOrConnection);
public:
DataContext(System::String ^ connectionString);
public DataContext (string fileOrServerOrConnection);
public DataContext (string connectionString);
new System.Data.Linq.DataContext : string -> System.Data.Linq.DataContext
new System.Data.Linq.DataContext : string -> System.Data.Linq.DataContext
Public Sub New (fileOrServerOrConnection As String)
Public Sub New (connectionString As String)
Parâmetros
- fileOrServerOrConnectionconnectionString
- String
Esse argumento pode ser um dos seguintes: o nome de um arquivo no qual reside um banco de dados do SQL Server Express.This argument can be any one of the following: The name of a file where a SQL Server Express database resides.
O nome de um servidor em que existe um banco de dados.The name of a server where a database is present. Nesse caso, o provedor usa o banco de dados padrão de um usuário.In this case the provider uses the default database for a user.
Uma cadeia de conexão completa.A complete connection string. O LINQ to SQL passa apenas a cadeia de caracteres para o provedor sem modificação.LINQ to SQL just passes the string to the provider without modification.