Using advWorksContext As New AdventureWorksEntities
Try
Dim entity As Object = Nothing
Dim entityKeyValues As IEnumerable(Of KeyValuePair(Of String, Object)) = _
New KeyValuePair(Of String, Object)() { _
New KeyValuePair(Of String, Object)("SalesOrderID", 43680)}
' Create the key for a specific SalesOrderHeader object.
Dim key As New EntityKey("AdventureWorksEntities.SalesOrderHeader", entityKeyValues)
' Try to get the object from the context or the persisted store by its key.
If advWorksContext.TryGetObjectByKey(key, entity) Then
Console.WriteLine("The requested " & entity.GetType().FullName & _
" object was found")
Else
Console.WriteLine("An object with this key " & _
"could not be found.")
End If
Catch ex As EntitySqlException
Console.WriteLine(ex.ToString)
End Try
End Using