Redigera

Dela via


DataContext Constructors

Definition

Initializes a new instance of the DataContext class. The connection string you use can be an ADO.NET connection string. You can also specify a filename to a SQL Server Express or SQL Server Compact file.

Overloads

DataContext(IDbConnection)

Initializes a new instance of the DataContext class by referencing the connection used by the .NET Framework.

DataContext(String)

Initializes a new instance of the DataContext class by referencing a file source.

DataContext(IDbConnection, MappingSource)

Initializes a new instance of the DataContext class by referencing a connection and a mapping source.

DataContext(String, MappingSource)

Initializes a new instance of the DataContext class by referencing a file source and a mapping source.

DataContext(IDbConnection)

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)

Parameters

connection
IDbConnection

The connection used by the .NET Framework.

Remarks

A DataContext opens and closes a database connection as needed if you provide a closed connection or a connection string. In general, you should never have to call Dispose on a DataContext. If you provide an open connection, the DataContext will not close it. Therefore, do not instantiate a DataContext with an open connection unless you have a good reason to do this. In a System.Transactions transaction, a DataContext will not open or close a connection to avoid promotion.

Applies to

DataContext(String)

Initializes a new instance of the DataContext class by referencing a file source.

public:
 DataContext(System::String ^ fileOrServerOrConnection);
public DataContext (string fileOrServerOrConnection);
new System.Data.Linq.DataContext : string -> System.Data.Linq.DataContext
Public Sub New (fileOrServerOrConnection As String)

Parameters

fileOrServerOrConnection
String

This argument can be any one of the following: The name of a file where a SQL Server Express database resides.

The name of a server where a database is present. In this case the provider uses the default database for a user.

A complete connection string. LINQ to SQL just passes the string to the provider without modification.

Applies to

DataContext(IDbConnection, MappingSource)

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)

Parameters

connection
IDbConnection

The connection used by the .NET Framework.

mapping
MappingSource

A source for mapping.

Applies to

DataContext(String, MappingSource)

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)

Parameters

fileOrServerOrConnection
String

This argument can be any one of the following:

The name of a file where a SQL Server Express database resides.

The name of a server where a database is present. In this case the provider uses the default database for a user.

A complete connection string. LINQ to SQL just passes the string to the provider without modification.

mapping
MappingSource

A source for mapping.

Applies to