DataContext DataContext DataContext DataContext Class

定義

表示 LINQ to SQL 架構的主要進入點。Represents the main entry point for the LINQ to SQL framework.

public ref class DataContext : IDisposable
public class DataContext : IDisposable
type DataContext = class
    interface IDisposable
Public Class DataContext
Implements IDisposable
繼承
DataContextDataContextDataContextDataContext
實作

備註

DataContext對應資料庫連接的所有實體的來源。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.

一般情況下,DataContext執行個體是最後一個 「 工作單元 」 不過您的應用程式會定義該字詞。In general, a DataContext instance is designed to last for one "unit of work" however your application defines that term. ADataContext是輕量且不耗費大量資源。A DataContext is lightweight and is not expensive to create. 典型LINQ to SQLLINQ to SQL應用程式會建立DataContext在方法範圍內,或為短期的類別,代表一組邏輯的成員執行個體相關的資料庫作業。A typical LINQ to SQLLINQ 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.

建構函式

DataContext(IDbConnection) DataContext(IDbConnection) DataContext(IDbConnection) DataContext(IDbConnection)

初始化的新執行個體DataContext類別,藉由參考所使用的連接.NET Framework.NET FrameworkInitializes a new instance of the DataContext class by referencing the connection used by the .NET Framework.NET Framework.

DataContext(IDbConnection, MappingSource) DataContext(IDbConnection, MappingSource) DataContext(IDbConnection, MappingSource) DataContext(IDbConnection, MappingSource)

初始化的新執行個體DataContext類別參考連接和對應來源。Initializes a new instance of the DataContext class by referencing a connection and a mapping source.

DataContext(String) DataContext(String) DataContext(String) DataContext(String)

初始化的新執行個體DataContext藉由參考檔案來源的類別。Initializes a new instance of the DataContext class by referencing a file source.

DataContext(String, MappingSource) DataContext(String, MappingSource) DataContext(String, MappingSource) DataContext(String, MappingSource)

初始化的新執行個體DataContext類別參考檔案來源和對應來源。Initializes a new instance of the DataContext class by referencing a file source and a mapping source.

屬性

ChangeConflicts ChangeConflicts ChangeConflicts ChangeConflicts

取得導致並行存取衝突的物件的集合時SubmitChanges()呼叫。Gets a collection of objects that caused concurrency conflicts when SubmitChanges() was called.

CommandTimeout CommandTimeout CommandTimeout CommandTimeout

取得或設定值,該值會增加查詢的逾時期間 (以秒為單位),否則查詢會在預設逾時期間內逾時。Gets or sets a value that increases the time-out period (in seconds) for queries that would otherwise time out during the default time-out period.

Connection Connection Connection Connection

取得架構所使用的連接。Gets the connection used by the framework.

DeferredLoadingEnabled DeferredLoadingEnabled DeferredLoadingEnabled DeferredLoadingEnabled

取得或設定值,這個值,指出是否要延遲載入-從一對多或一對一關聯性。Gets or sets a value that indicates whether to delay-load one-to-many or one-to-one relationships.

LoadOptions LoadOptions LoadOptions LoadOptions

取得或設定DataLoadOptions與此相關聯DataContextGets or sets the DataLoadOptions associated with this DataContext.

Log Log Log Log

取得或設定目的地,以撰寫 SQL 查詢或命令。Gets or sets the destination to write the SQL query or command.

Mapping Mapping Mapping Mapping

取得MetaModel依據對應。Gets the MetaModel on which the mapping is based.

ObjectTrackingEnabled ObjectTrackingEnabled ObjectTrackingEnabled ObjectTrackingEnabled

取得或設定值,這個值,指出是否已啟用追蹤的物件。Gets or sets a value that indicates whether object tracking is enabled.

QueryCacheEnabled QueryCacheEnabled QueryCacheEnabled QueryCacheEnabled
Transaction Transaction Transaction Transaction

取得或設定的本機交易.NET Framework.NET Framework用來存取資料庫。Gets or sets a local transaction for the .NET Framework.NET Framework to use to access the database.

方法

CreateDatabase() CreateDatabase() CreateDatabase() CreateDatabase()

在伺服器上建立資料庫。Creates a database on the server.

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

執行與指定之 .NET 方法關聯的資料表值資料庫函式。Executes the table-valued database function associated with the specified .NET method.

DatabaseExists() DatabaseExists() DatabaseExists() DatabaseExists()

判斷是否可以開啟相關聯的資料庫。Determines whether the associated database can be opened.

DeleteDatabase() DeleteDatabase() DeleteDatabase() DeleteDatabase()

會刪除相關聯的資料庫。Deletes the associated database.

Dispose() Dispose() Dispose() Dispose()

釋放 DataContext 類別目前的執行個體所使用的全部資源。Releases all resources used by the current instance of the DataContext class.

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

釋放所使用的 unmanaged 的資源DataContext類別,並選擇性地釋放 managed 的資源。Releases the unmanaged resources used by the DataContext class and optionally releases the managed resource.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
ExecuteCommand(String, Object[]) ExecuteCommand(String, Object[]) ExecuteCommand(String, Object[]) ExecuteCommand(String, Object[])

直接在資料庫上執行 SQL 命令。Executes SQL commands directly on the database.

ExecuteDynamicDelete(Object) ExecuteDynamicDelete(Object) ExecuteDynamicDelete(Object) ExecuteDynamicDelete(Object)

若要重新委派給刪除覆寫方法內執行LINQ to SQLLINQ to SQL的動態 SQL 產生與執行的工作會刪除作業。Executes, inside delete override methods, to redelegate to LINQ to SQLLINQ to SQL the task of generating and executing dynamic SQL for delete operations.

ExecuteDynamicInsert(Object) ExecuteDynamicInsert(Object) ExecuteDynamicInsert(Object) ExecuteDynamicInsert(Object)

在插入覆寫方法內執行,以將插入作業所需的動態 SQL 產生與執行工作重新委派給 LINQ to SQLLINQ to SQLExecutes, inside insert override methods, to redelegate to LINQ to SQLLINQ to SQL the task of generating and executing dynamic SQL for insert operations.

ExecuteDynamicUpdate(Object) ExecuteDynamicUpdate(Object) ExecuteDynamicUpdate(Object) ExecuteDynamicUpdate(Object)

若要重新委派給的更新覆寫方法內執行LINQ to SQLLINQ to SQL進行更新作業的動態 SQL 產生與執行的工作。Executes, inside update override methods, to redelegate to LINQ to SQLLINQ to SQL the task of generating and executing dynamic SQL for update operations.

ExecuteMethodCall(Object, MethodInfo, Object[]) ExecuteMethodCall(Object, MethodInfo, Object[]) ExecuteMethodCall(Object, MethodInfo, Object[]) ExecuteMethodCall(Object, MethodInfo, Object[])

執行與指定之 .NET 方法關聯的預存資料庫程序或純量函式。Executes the stored database procedure or scalar function associated with the specified .NET method.

ExecuteQuery(Type, String, Object[]) ExecuteQuery(Type, String, Object[]) ExecuteQuery(Type, String, Object[]) ExecuteQuery(Type, String, Object[])

直接在資料庫上執行 SQL 查詢。Executes SQL queries directly on the database.

ExecuteQuery<TResult>(String, Object[]) ExecuteQuery<TResult>(String, Object[]) ExecuteQuery<TResult>(String, Object[]) ExecuteQuery<TResult>(String, Object[])

直接在資料庫上執行 SQL 查詢,並傳回物件。Executes SQL queries directly on the database and returns objects.

GetChangeSet() GetChangeSet() GetChangeSet() GetChangeSet()

取得已修改的物件,由追蹤DataContextGets the modified objects tracked by DataContext.

GetCommand(IQueryable) GetCommand(IQueryable) GetCommand(IQueryable) GetCommand(IQueryable)

取得所產生的 SQL 命令的相關資訊LINQ to SQLLINQ to SQLGets the information about SQL commands generated by LINQ to SQLLINQ to SQL.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetIDbCommand(IQueryable) GetIDbCommand(IQueryable) GetIDbCommand(IQueryable) GetIDbCommand(IQueryable)
GetTable(Type) GetTable(Type) GetTable(Type) GetTable(Type)

傳回特定的類型,類型由所定義之物件的集合type參數。Returns a collection of objects of a particular type, where the type is defined by the type parameter.

GetTable<TEntity>() GetTable<TEntity>() GetTable<TEntity>() GetTable<TEntity>()

傳回特定的類型,類型由所定義之物件的集合TEntity參數。Returns a collection of objects of a particular type, where the type is defined by the TEntity parameter.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(Inherited from Object)
Refresh(RefreshMode, IEnumerable) Refresh(RefreshMode, IEnumerable) Refresh(RefreshMode, IEnumerable) Refresh(RefreshMode, IEnumerable)

重新整理實體物件,根據指定的模式的集合。Refreshes a collection of entity objects according to the specified mode.

Refresh(RefreshMode, Object) Refresh(RefreshMode, Object) Refresh(RefreshMode, Object) Refresh(RefreshMode, Object)

重新整理實體物件根據指定的模式。Refreshes an entity object according to the specified mode.

Refresh(RefreshMode, Object[]) Refresh(RefreshMode, Object[]) Refresh(RefreshMode, Object[]) Refresh(RefreshMode, Object[])

重新整理實體物件,根據指定的模式的陣列。Refreshes an array of entity objects according to the specified mode.

SubmitChanges() SubmitChanges() SubmitChanges() 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) SubmitChanges(ConflictMode) SubmitChanges(ConflictMode) 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() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)
Translate(DbDataReader) Translate(DbDataReader) Translate(DbDataReader) Translate(DbDataReader)

將轉換的現有DbDataReader物件。Converts an existing DbDataReader to objects.

Translate(Type, DbDataReader) Translate(Type, DbDataReader) Translate(Type, DbDataReader) Translate(Type, DbDataReader)

將轉換的現有DbDataReader物件。Converts an existing DbDataReader to objects.

Translate<TResult>(DbDataReader) Translate<TResult>(DbDataReader) Translate<TResult>(DbDataReader) Translate<TResult>(DbDataReader)

將轉換的現有DbDataReader物件。Converts an existing DbDataReader to objects.

適用於