ObjectContext.TryGetObjectByKey 方法
[此頁面專屬於 Entity Framework 第 6 版。最新版本可從 'Entity Framework' NuGet 套件取得。如需 Entity Framework 的詳細資訊,請參閱 msdn.com/data/ef。]
傳回具有指定之實體索引鍵的物件。
命名空間: System.Data.Entity.Core.Objects
組件: EntityFramework (在 EntityFramework.dll 中)
語法
'宣告
<SuppressMessageAttribute("Microsoft.Design", "CA1007:UseGenericsWhereAppropriate")> _
Public Overridable Function TryGetObjectByKey ( _
key As EntityKey, _
<OutAttribute> ByRef value As Object _
) As Boolean
'用途
Dim instance As ObjectContext
Dim key As EntityKey
Dim value As Object
Dim returnValue As Boolean
returnValue = instance.TryGetObjectByKey(key, _
value)
[SuppressMessageAttribute("Microsoft.Design", "CA1007:UseGenericsWhereAppropriate")]
public virtual bool TryGetObjectByKey(
EntityKey key,
out Object value
)
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1007:UseGenericsWhereAppropriate")]
public:
virtual bool TryGetObjectByKey(
EntityKey^ key,
[OutAttribute] Object^% value
)
[<SuppressMessageAttribute("Microsoft.Design", "CA1007:UseGenericsWhereAppropriate")>]
abstract TryGetObjectByKey :
key:EntityKey *
value:Object byref -> bool
[<SuppressMessageAttribute("Microsoft.Design", "CA1007:UseGenericsWhereAppropriate")>]
override TryGetObjectByKey :
key:EntityKey *
value:Object byref -> bool
public function TryGetObjectByKey(
key : EntityKey,
value : Object
) : boolean
參數
- key
類型:System.Data.Entity.Core.EntityKey
要尋找之物件的索引鍵。
- value
類型:System.Object%
在此方法傳回時,它會包含此物件。
傳回值
類型:System.Boolean
如果擷取物件成功則為 true。如果 key 是暫存的、connection 為 null 或 value 為 null,則為 false。
例外狀況
例外狀況 | 條件 |
---|---|
ArgumentException | key 的中繼資料不相容。 |
ArgumentNullException | key 為 null。 |