EntityKey Class
This page is specific to:.NET Framework Version:3.54.0
.NET Framework Class Library
EntityKey Class

Provides a durable reference to an object that is an instance of an entity type.

Namespace:  System.Data
Assembly:  System.Data.Entity (in System.Data.Entity.dll)
Syntax

'Usage

Dim instance As EntityKey

'Declaration

<SerializableAttribute> _
<DataContractAttribute(IsReference := True)> _
Public NotInheritable Class EntityKey _
    Implements IEquatable(Of EntityKey)
Remarks

The EntityKey objects are immutable; that is, after they are constructed they cannot be modified.

For more information, see Working with Entity Keys (Entity Framework).

Examples

These examples are based on the Adventure Works Sales Model. The examples show you how to create and use an EntityKey.

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


Inheritance Hierarchy

System..::.Object
  System.Data..::.EntityKey
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5 SP1
See Also

Reference

Other Resources

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View