共用方式為


DataServiceContext.TryGetEntity<TEntity> 方法

透過實體 URI 的參考進行測試擷取 DataServiceContext 正在追蹤的實體。

命名空間:  System.Data.Services.Client
組件:  Microsoft.Data.Services.Client (在 Microsoft.Data.Services.Client.dll 中)

語法

'宣告
Public Function TryGetEntity(Of TEntity As Class) ( _
    identity As Uri, _
    <OutAttribute> ByRef entity As TEntity _
) As Boolean
'用途
Dim instance As DataServiceContext
Dim identity As Uri
Dim entity As TEntity
Dim returnValue As Boolean

returnValue = instance.TryGetEntity(identity, _
    entity)
public bool TryGetEntity<TEntity>(
    Uri identity,
    out TEntity entity
)
where TEntity : class
public:
generic<typename TEntity>
where TEntity : ref class
bool TryGetEntity(
    Uri^ identity, 
    [OutAttribute] TEntity% entity
)
member TryGetEntity : 
        identity:Uri * 
        entity:'TEntity byref -> bool  when 'TEntity : not struct
JScript 不支援泛型型別及方法。

型別參數

  • TEntity
    實體的型別。

參數

  • identity
    型別:System.Uri
    要擷取之追蹤實體的 URI。
  • entity
    型別:TEntity%
    要擷取的實體。

傳回值

型別:System.Boolean
如果在 resourceUri 找到實體,則會以 out 參數 entity 傳回實體,並且傳回 true。如果找不到實體,則會傳回 false。

例外狀況

例外狀況 條件
ArgumentNullException

當 identity 為 nullnull 參考 (在 Visual Basic 中為 Nothing) 時。

備註

如果實體處於 DetachedAdded 狀態,它並沒有 URI,也不能使用此方法擷取。

請參閱

參考

DataServiceContext 類別

System.Data.Services.Client 命名空間