EntityKey 클래스

정의

엔터티 형식의 인스턴스인 개체에 대한 영구 참조를 제공합니다.Provides a durable reference to an object that is an instance of an entity type.

public ref class EntityKey sealed : IEquatable<System::Data::EntityKey ^>
[System.Runtime.Serialization.DataContract(IsReference=true)]
[System.Serializable]
public sealed class EntityKey : IEquatable<System.Data.EntityKey>
[<System.Runtime.Serialization.DataContract(IsReference=true)>]
[<System.Serializable>]
type EntityKey = class
    interface IEquatable<EntityKey>
Public NotInheritable Class EntityKey
Implements IEquatable(Of EntityKey)
상속
EntityKey
특성
구현

예제

이러한 예제는 Microsoft SQL Server 제품 샘플: 데이터베이스를 기반으로 합니다.These examples are based on the Microsoft SQL Server Product Samples: Database. 예제를 만들고 사용 하는 방법을 보여는 EntityKey합니다.The examples show you how to create and use an EntityKey.

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    Object entity = null;
    IEnumerable<KeyValuePair<string, object>> entityKeyValues =
        new KeyValuePair<string, object>[] {
            new KeyValuePair<string, object>("SalesOrderID", 43680) };

    // Create the  key for a specific SalesOrderHeader object.
    EntityKey key = new EntityKey("AdventureWorksEntities.SalesOrderHeaders", entityKeyValues);

    // Get the object from the context or the persisted store by its key.
    if (context.TryGetObjectByKey(key, out entity))
    {
        Console.WriteLine("The requested " + entity.GetType().FullName +
            " object was found");
    }
    else
    {
        Console.WriteLine("An object with this key " +
            "could not be found.");
    }
}
Using context As New AdventureWorksEntities()
    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.SalesOrderHeaders", entityKeyValues)

    ' Get the object from the context or the persisted store by its key. 
    If context.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
End Using
using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    try
    {
        // Create the key that represents the order.
        EntityKey orderKey =
            new EntityKey("AdventureWorksEntities.SalesOrderHeaders",
                "SalesOrderID", orderId);

        // Create the stand-in SalesOrderHeader object
        // based on the specified SalesOrderID.
        SalesOrderHeader order = new SalesOrderHeader();
        order.EntityKey = orderKey;

        // Assign the ID to the SalesOrderID property to matche the key.
        order.SalesOrderID = (int)orderKey.EntityKeyValues[0].Value;

        // Attach the stand-in SalesOrderHeader object.
        context.SalesOrderHeaders.Attach(order);

        // Create a new SalesOrderDetail object.
        // You can use the static CreateObjectName method (the Entity Framework
        // adds this method to the generated entity types) instead of the new operator:
        // SalesOrderDetail.CreateSalesOrderDetail(1, 0, 2, 750, 1, (decimal)2171.2942, 0, 0,
        //                                         Guid.NewGuid(), DateTime.Today));
        SalesOrderDetail detail = new SalesOrderDetail
        {
            SalesOrderID = orderId,
            SalesOrderDetailID = 0,
            OrderQty = 2,
            ProductID = 750,
            SpecialOfferID = 1,
            UnitPrice = (decimal)2171.2942,
            UnitPriceDiscount = 0,
            LineTotal = 0,
            rowguid = Guid.NewGuid(),
            ModifiedDate = DateTime.Now
        };

        order.SalesOrderDetails.Add(detail);

        context.SaveChanges();
    }
    catch (InvalidOperationException)
    {
        Console.WriteLine("Ensure that the key value matches the value of the object's ID property.");
    }
    catch (UpdateException)
    {
        Console.WriteLine("An error has occurred. Ensure that an object with the '{0}' key value exists.",
        orderId);
    }
}
Using context As New AdventureWorksEntities()
    Try
        ' Create the key that represents the order. 
        Dim orderKey As New EntityKey("AdventureWorksEntities.SalesOrderHeaders", "SalesOrderID", orderId)

        ' Create the stand-in SalesOrderHeader object 
        ' based on the specified SalesOrderID. 
        Dim order As New SalesOrderHeader()
        order.EntityKey = orderKey

        ' Assign the ID to the SalesOrderID property to matche the key. 
        order.SalesOrderID = CInt(orderKey.EntityKeyValues(0).Value)

        ' Attach the stand-in SalesOrderHeader object. 
        context.SalesOrderHeaders.Attach(order)

        ' Create a new SalesOrderDetail object. 
        ' You can use the static CreateObjectName method (the Entity Framework 
        ' adds this method to the generated entity types) instead of the new operator: 
        ' SalesOrderDetail.CreateSalesOrderDetail(1, 0, 2, 750, 1, (decimal)2171.2942, 0, 0, 
        ' Guid.NewGuid(), DateTime.Today)); 
        Dim detail = New SalesOrderDetail With
        {
            .SalesOrderID = 0,
            .SalesOrderDetailID = 0,
            .OrderQty = 2,
            .ProductID = 750,
            .SpecialOfferID = 1,
            .UnitPrice = CDec(2171.2942),
            .UnitPriceDiscount = 0,
            .LineTotal = 0,
            .rowguid = Guid.NewGuid(),
            .ModifiedDate = DateTime.Now
        }

        order.SalesOrderDetails.Add(detail)

        context.SaveChanges()
    Catch generatedExceptionName As InvalidOperationException
        Console.WriteLine("Ensure that the key value matches the value of the object's ID property.")
    Catch generatedExceptionName As UpdateException
        Console.WriteLine("An error has occurred. Ensure that an object with the '{0}' key value exists.", orderId)
    End Try
End Using

설명

EntityKey 개체는 변경할 수 없습니다. 즉, 생성된 후에는 수정할 수 없습니다.The EntityKey objects are immutable; that is, after they are constructed they cannot be modified.

자세한 내용은 엔터티 키 작업합니다.For more information, see Working with Entity Keys.

생성자

EntityKey()

EntityKey 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the EntityKey class.

EntityKey(String, IEnumerable<EntityKeyMember>)

엔터티 집합 이름 및 EntityKey 개체의 IEnumerable<T> 컬렉션을 사용하여 EntityKeyMember 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the EntityKey class with an entity set name and an IEnumerable<T> collection of EntityKeyMember objects.

EntityKey(String, IEnumerable<KeyValuePair<String,Object>>)

엔터티 집합 이름 및 제네릭 EntityKey 컬렉션을 사용하여 KeyValuePair 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the EntityKey class with an entity set name and a generic KeyValuePair collection.

EntityKey(String, String, Object)

엔터티 집합 이름 및 특정 엔터티 키 쌍을 사용하여 EntityKey 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the EntityKey class with an entity set name and specific entity key pair.

필드

EntityNotValidKey

실패한 TREAT 연산의 결과인 엔터티를 식별하는 간단한 EntityKey입니다.A simple EntityKey identifying an entity that resulted from a failed TREAT operation.

NoEntitySetKey

읽기 전용 엔터티가 식별되는 singleton EntityKey입니다.A singleton EntityKey by which a read-only entity is identified.

속성

EntityContainerName

엔터티 컨테이너의 이름을 가져오거나 설정합니다.Gets or sets the name of the entity container.

EntityKeyValues

EntityKey와 연결된 키 값을 가져오거나 설정합니다.Gets or sets the key values associated with this EntityKey.

EntitySetName

엔터티 집합의 이름을 가져오거나 설정합니다.Gets or sets the name of the entity set.

IsTemporary

EntityKey가 임시인지 여부를 나타내는 값을 가져옵니다.Gets a value that indicates whether the EntityKey is temporary.

메서드

Equals(EntityKey)

이 인스턴스가 지정한 EntityKey와 같은지 여부를 나타내는 값을 반환합니다.Returns a value that indicates whether this instance is equal to a specified EntityKey.

Equals(Object)

@FSHO2@이 인스턴스가 지정한 개체와 같은지를 나타내는 값을 반환합니다.Returns a value that indicates whether this instance is equal to a specified object.

GetEntitySet(MetadataWorkspace)

지정된 메타데이터 작업 영역에서 이 엔터티 키에 대한 엔터티 집합을 가져옵니다.Gets the entity set for this entity key from the given metadata workspace.

GetHashCode()

현재 EntityKey 개체의 해시 함수로 사용됩니다.Serves as a hash function for the current EntityKey object. GetHashCode()는 해시 알고리즘 및 해시 테이블과 같은 데이터 구조에 적합합니다.GetHashCode() is suitable for hashing algorithms and data structures such as a hash table.

GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(다음에서 상속됨 Object)
OnDeserialized(StreamingContext)

EntityKey를 역직렬화하는 데 사용되는 도우미 메서드입니다.Helper method that is used to deserialize an EntityKey.

OnDeserializing(StreamingContext)

EntityKey를 역직렬화하는 데 사용되는 도우미 메서드입니다.Helper method that is used to deserialize an EntityKey.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(다음에서 상속됨 Object)

연산자

Equality(EntityKey, EntityKey)

두 개의 EntityKey 개체를 비교합니다.Compares two EntityKey objects.

Inequality(EntityKey, EntityKey)

두 개의 EntityKey 개체를 비교합니다.Compares two EntityKey objects.

적용 대상