DataContext 類別

定義

表示 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
繼承
DataContext
實作

備註

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. DataContext是輕量,而且建立的成本不高。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)

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

DataContext(IDbConnection, MappingSource)

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

DataContext(String)

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

DataContext(String, MappingSource)

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

屬性

ChangeConflicts

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

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

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

DeferredLoadingEnabled

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

LoadOptions

取得或設定與這個 DataLoadOptions 關聯的 DataContextGets or sets the DataLoadOptions associated with this DataContext.

Log

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

Mapping

取得做為對應之基礎的 MetaModelGets the MetaModel on which the mapping is based.

ObjectTrackingEnabled

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

QueryCacheEnabled
Transaction

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

方法

CreateDatabase()

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

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

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

DatabaseExists()

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

DeleteDatabase()

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

Dispose()

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

Dispose(Boolean)

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

Equals(Object)

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

(繼承來源 Object)
ExecuteCommand(String, Object[])

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

ExecuteDynamicDelete(Object)

在刪除覆寫方法內執行,以將刪除作業所需的動態 SQL 產生與執行工作重新委派給 LINQ to SQLLINQ to SQLExecutes, 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)

在插入覆寫方法內執行,以將插入作業所需的動態 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)

在更新覆寫方法內執行,以將更新作業所需的動態 SQL 產生與執行工作重新委派給 LINQ to SQLLINQ to SQLExecutes, 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[])

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

ExecuteQuery(Type, String, Object[])

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

ExecuteQuery<TResult>(String, Object[])

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

GetChangeSet()

取得 DataContext 所追蹤的已修改物件。Gets the modified objects tracked by DataContext.

GetCommand(IQueryable)

取得由 LINQ to SQLLINQ to SQL 產生之有關 SQL 命令的資訊。Gets the information about SQL commands generated by LINQ to SQLLINQ to SQL.

GetHashCode()

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

(繼承來源 Object)
GetIDbCommand(IQueryable)
GetTable(Type)

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

GetTable<TEntity>()

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

GetType()

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

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 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, 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.

(繼承來源 Object)
Translate(DbDataReader)

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

Translate(Type, DbDataReader)

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

Translate<TResult>(DbDataReader)

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

適用於