DataContext.Translate 方法

定義

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

多載

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.

備註

IDataReader 中的每個資料列都會轉換成 IEnumerable<T>中的物件。Each row in the IDataReader is converted to an object in the IEnumerable<T>.

public IEnumerable<T> Translate<T>(IDataReader reader) {}  

描述:這個方法可用來將現有的 DbDataReader 轉換成物件。Description: This method is used to convert an existing DbDataReader to objects. DbDataReader 中的每個資料列都會轉換成 IEnumerable<T>中的物件。Each row in the DbDataReader is converted to an object in the IEnumerable<T>.

一般參數:Generic parameters:

T:請參閱 ExecuteQueryT: See ExecuteQuery.

參數:Parameters:

Query:請參閱 ExecuteCommand下的命令說明。Query: See the description for command under ExecuteCommand.

Parameters:請參閱 ExecuteCommand下的參數說明。Parameters: See the description for parameters under ExecuteCommand.

傳回類型:Return type:

IEnumerable<T>:轉換所傳回的物件集合。IEnumerable<T>: collection of objects returned by the conversion.

Translate(DbDataReader)

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

public:
 System::Data::Linq::IMultipleResults ^ Translate(System::Data::Common::DbDataReader ^ reader);
public System.Data.Linq.IMultipleResults Translate (System.Data.Common.DbDataReader reader);
member this.Translate : System.Data.Common.DbDataReader -> System.Data.Linq.IMultipleResults
Public Function Translate (reader As DbDataReader) As IMultipleResults

參數

reader
DbDataReader

要轉換的 IDataReaderThe IDataReader to be converted.

傳回

轉換所傳回的物件清單。A list of objects returned by the conversion.

Translate(Type, DbDataReader)

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

public:
 System::Collections::IEnumerable ^ Translate(Type ^ elementType, System::Data::Common::DbDataReader ^ reader);
public System.Collections.IEnumerable Translate (Type elementType, System.Data.Common.DbDataReader reader);
member this.Translate : Type * System.Data.Common.DbDataReader -> System.Collections.IEnumerable
Public Function Translate (elementType As Type, reader As DbDataReader) As IEnumerable

參數

elementType
Type

要傳回的 IEnumerable<T> 型別。The type of the IEnumerable<T> to be returned.

結果中的資料行與物件運作中的欄位和屬性相符合的演算法用法如下:The algorithm for matching columns in the result to fields and properties in the object works as follows: 如果欄位或屬性已對應至特定資料行名稱,結果集 (Resultset) 必須包含該資料行名稱。If a field or property is mapped to a particular column name, that column name is expected in the resultset.

如果欄位或屬性未對應,結果集必須包含與該欄位或屬性同名的資料行。If a field or property is not mapped, a column with the same name as the field or property is expected in the resultset.

尋找區分大小寫的相符項時會先進行比較。The comparison is performed by looking for a case-sensitive match first. 如果找不到這種相符項,就會繼續搜尋不區分大小寫的相符項。If this match is not found, a subsequent search is occurs for a case-insensitive match.

當下列所有條件皆為 true 時,查詢必須傳回該物件所有追蹤的欄位和屬性 (會延後載入的欄位和屬性除外):The query must return all the tracked fields and properties of the object (except those that are loaded on a deferred basis) when all the following conditions are true: TDataContext 明確追蹤的實體。T is an entity explicitly tracked by the DataContext.

ObjectTrackingEnabled 上所宣告的預設值是 trueObjectTrackingEnabled is true.

這個實體具有主索引鍵。The entity has a primary key.

否則,會擲回例外狀況。Otherwise an exception is thrown.

reader
DbDataReader

要轉換的 IDataReaderThe IDataReader to be converted.

傳回

轉換所傳回的物件清單。A list of objects returned by the conversion.

Translate<TResult>(DbDataReader)

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

public:
generic <typename TResult>
 System::Collections::Generic::IEnumerable<TResult> ^ Translate(System::Data::Common::DbDataReader ^ reader);
public System.Collections.Generic.IEnumerable<TResult> Translate<TResult> (System.Data.Common.DbDataReader reader);
member this.Translate : System.Data.Common.DbDataReader -> seq<'Result>
Public Function Translate(Of TResult) (reader As DbDataReader) As IEnumerable(Of TResult)

類型參數

TResult

要傳回的 IEnumerable<T> 型別。The type of the IEnumerable<T> to be returned.

參數

reader
DbDataReader

要轉換的 IDataReaderThe IDataReader to be converted.

傳回

IEnumerable<TResult>

轉換所傳回的物件集合。A collection of objects returned by the conversion.

適用於