Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DataContext Class

 

Represents the main entry point for the LINQ to SQL framework.

Namespace:   System.Data.Linq
Assembly:  System.Data.Linq (in System.Data.Linq.dll)

System.Object
  System.Data.Linq.DataContext

public class DataContext : IDisposable

NameDescription
System_CAPS_pubmethodDataContext(IDbConnection)

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

System_CAPS_pubmethodDataContext(IDbConnection, MappingSource)

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

System_CAPS_pubmethodDataContext(String)

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

System_CAPS_pubmethodDataContext(String, MappingSource)

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

NameDescription
System_CAPS_pubpropertyChangeConflicts

Gets a collection of objects that caused concurrency conflicts when SubmitChanges was called.

System_CAPS_pubpropertyCommandTimeout

Gets or sets a value that increases the time-out period for queries that would otherwise time out during the default time-out period.

System_CAPS_pubpropertyConnection

Gets the connection used by the framework.

System_CAPS_pubpropertyDeferredLoadingEnabled

Gets or sets a value that indicates whether to delay-load one-to-many or one-to-one relationships.

System_CAPS_pubpropertyLoadOptions

Gets or sets the DataLoadOptions associated with this DataContext.

System_CAPS_pubpropertyLog

Gets or sets the destination to write the SQL query or command.

System_CAPS_pubpropertyMapping

Gets the MetaModel on which the mapping is based.

System_CAPS_pubpropertyObjectTrackingEnabled

Gets or sets a value that indicates whether object tracking is enabled.

System_CAPS_pubpropertyTransaction

Gets or sets a local transaction for the .NET Framework to use to access the database.

NameDescription
System_CAPS_pubmethodCreateDatabase()

Creates a database on the server.

System_CAPS_protmethodCreateMethodCallQuery<TResult>(Object, MethodInfo, Object[])

This API supports the product infrastructure and is not intended to be used directly from your code. Executes the table-valued database function associated with the specified CLR method.

System_CAPS_pubmethodDatabaseExists()

Determines whether the associated database can be opened.

System_CAPS_pubmethodDeleteDatabase()

Deletes the associated database.

System_CAPS_pubmethodDispose()

Releases all resources used by the current instance of the DataContext class.

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the DataContext class and optionally releases the managed resource.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodExecuteCommand(String, Object[])

Executes SQL commands directly on the database.

System_CAPS_protmethodExecuteDynamicDelete(Object)

Executes, inside delete override methods, to redelegate to LINQ to SQL the task of generating and executing dynamic SQL for delete operations.

System_CAPS_protmethodExecuteDynamicInsert(Object)

Executes, inside insert override methods, to redelegate to LINQ to SQL the task of generating and executing dynamic SQL for insert operations.

System_CAPS_protmethodExecuteDynamicUpdate(Object)

Executes, inside update override methods, to redelegate to LINQ to SQL the task of generating and executing dynamic SQL for update operations.

System_CAPS_protmethodExecuteMethodCall(Object, MethodInfo, Object[])

This API supports the product infrastructure and is not intended to be used directly from your code. Executes the stored database procedure or scalar function associated with the specified CLR method.

System_CAPS_pubmethodExecuteQuery(Type, String, Object[])

Executes SQL queries directly on the database.

System_CAPS_pubmethodExecuteQuery<TResult>(String, Object[])

Executes SQL queries directly on the database and returns objects.

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetChangeSet()

Gets the modified objects tracked by DataContext.

System_CAPS_pubmethodGetCommand(IQueryable)

Gets the information about SQL commands generated by LINQ to SQL.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetTable(Type)

Returns a collection of objects of a particular type, where the type is defined by the type parameter.

System_CAPS_pubmethodGetTable<TEntity>()

Returns a collection of objects of a particular type, where the type is defined by the TEntity parameter.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodRefresh(RefreshMode, IEnumerable)

Refreshes a collection of entity objects according to the specified mode.

System_CAPS_pubmethodRefresh(RefreshMode, Object)

Refreshes an entity object according to the specified mode.

System_CAPS_pubmethodRefresh(RefreshMode, Object[])

Refreshes an array of entity objects according to the specified mode.

System_CAPS_pubmethodSubmitChanges()

Computes the set of modified objects to be inserted, updated, or deleted, and executes the appropriate commands to implement the changes to the database.

System_CAPS_pubmethodSubmitChanges(ConflictMode)

Sends changes that were made to retrieved objects to the underlying database, and specifies the action to be taken if the submission fails.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodTranslate(DbDataReader)

Converts an existing DbDataReader to objects.

System_CAPS_pubmethodTranslate(Type, DbDataReader)

Converts an existing DbDataReader to objects.

System_CAPS_pubmethodTranslate<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.

.NET Framework
Available since 3.5
Windows Phone Silverlight
Available since 7.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft