DataContext Class
Represents the main entry point for the LINQ to SQL framework.
Assembly: System.Data.Linq (in System.Data.Linq.dll)
The DataContext type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | 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. |
| Name | Description | |
|---|---|---|
![]() | ChangeConflicts | Returns a collection of objects that caused concurrency conflicts when SubmitChanges was called. |
![]() | CommandTimeout | Increases the time-out period for queries that would otherwise time out during the default time-out period. |
![]() | Connection | Returns the connection used by the framework. |
![]() | DeferredLoadingEnabled | Specifies whether to delay-load one-to-many or one-to-one relationships. |
![]() | LoadOptions | Gets or sets the DataLoadOptions associated with this DataContext. |
![]() | Log | Specifies the destination to write the SQL query or command. |
![]() | Mapping | Returns the MetaModel on which the mapping is based. |
![]() | ObjectTrackingEnabled | Instructs the framework to track the original value and object identity for this DataContext. |
![]() | Transaction | Sets a local transaction for the .NET Framework to use to access the database. |
| Name | Description | |
|---|---|---|
![]() | CreateDatabase | Creates a database on the server. |
![]() | CreateMethodCallQuery<TResult> | Infrastructure. Executes the table-valued database function associated with the specified CLR method. |
![]() | DatabaseExists | Determines whether the associated database can be opened. |
![]() | DeleteDatabase | Deletes the associated database. |
![]() | Dispose() | Releases all resources used by the DataContext. |
![]() | Dispose(Boolean) | Releases resources used by the DataContext. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | ExecuteCommand | Executes SQL commands directly on the database. |
![]() | ExecuteDynamicDelete | Called inside delete override methods to redelegate to LINQ to SQL the task of generating and executing dynamic SQL for delete operations. |
![]() | ExecuteDynamicInsert | Called inside insert override methods to redelegate to LINQ to SQL the task of generating and executing dynamic SQL for insert operations. |
![]() | ExecuteDynamicUpdate | Called inside update override methods to redelegate to LINQ to SQL the task of generating and executing dynamic SQL for update operations. |
![]() | ExecuteMethodCall | Infrastructure. Executes the stored database procedure or scalar function associated with the specified CLR method. |
![]() | ExecuteQuery(Type, String, array<Object>) | Executes SQL queries directly on the database. |
![]() | ExecuteQuery<TResult>(String, array<Object>) | Executes SQL queries directly on the database and returns objects. |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetChangeSet | Provides access to the modified objects tracked by DataContext. |
![]() | GetCommand | Provides information about SQL commands generated by LINQ to SQL. |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetTable(Type) | Returns a collection of objects of a particular type, where the type is defined by the type parameter. |
![]() | GetTable<TEntity>() | Returns a collection of objects of a particular type, where the type is defined by the TEntity parameter. |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | Refresh(RefreshMode, IEnumerable) | Refreshes a collection of entity objects according to the specified mode. |
![]() | Refresh(RefreshMode, Object) | Refreshes an entity object according to the specified mode. |
![]() | Refresh(RefreshMode, array<Object>) | Refreshes an array of entity objects according to the specified mode. |
![]() | SubmitChanges() | Computes the set of modified objects to be inserted, updated, or deleted, and executes the appropriate commands to implement the changes to the database. |
![]() | SubmitChanges(ConflictMode) | Sends changes that were made to retrieved objects to the underlying database, and specifies the action to be taken if the submission fails. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | Translate(DbDataReader) | Converts an existing DbDataReader to objects. |
![]() | Translate(Type, DbDataReader) | Converts an existing DbDataReader to objects. |
![]() | Translate<TResult>(DbDataReader) | Converts an existing DbDataReader to objects. |
The DataContext is the source of all entities mapped over a database connection. It tracks changes that you made to all retrieved entities and maintains an "identity cache" that guarantees that entities retrieved more than one time are represented by using the same object instance.
In general, a DataContext instance is designed to last for one "unit of work" however your application defines that term. A DataContext is lightweight and is not expensive to create. A typical LINQ to SQL application creates DataContext instances at method scope or as a member of short-lived classes that represent a logical set of related database operations.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.


