EntityKey 클래스

정의

엔터티 형식의 인스턴스인 개체에 대한 영구 참조를 제공합니다.

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
특성
구현

예제

다음 예제에서는 를 만들고 사용하는 방법을 보여 줍니다 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 (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);
    }
}

설명

EntityKey 개체는 변경할 수 없습니다. 즉, 생성된 후에는 수정할 수 없습니다.

자세한 내용은 엔터티 키 작업합니다.

생성자

EntityKey()

EntityKey 클래스의 새 인스턴스를 초기화합니다.

EntityKey(String, IEnumerable<EntityKeyMember>)

엔터티 집합 이름 및 EntityKey 개체의 IEnumerable<T> 컬렉션을 사용하여 EntityKeyMember 클래스의 새 인스턴스를 초기화합니다.

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

엔터티 집합 이름 및 제네릭 EntityKey 컬렉션을 사용하여 KeyValuePair 클래스의 새 인스턴스를 초기화합니다.

EntityKey(String, String, Object)

엔터티 집합 이름 및 특정 엔터티 키 쌍을 사용하여 EntityKey 클래스의 새 인스턴스를 초기화합니다.

필드

EntityNotValidKey

실패한 TREAT 연산의 결과인 엔터티를 식별하는 간단한 EntityKey입니다.

NoEntitySetKey

읽기 전용 엔터티가 식별되는 singleton EntityKey입니다.

속성

EntityContainerName

엔터티 컨테이너의 이름을 가져오거나 설정합니다.

EntityKeyValues

EntityKey와 연결된 키 값을 가져오거나 설정합니다.

EntitySetName

엔터티 집합의 이름을 가져오거나 설정합니다.

IsTemporary

EntityKey가 임시인지 여부를 나타내는 값을 가져옵니다.

메서드

Equals(EntityKey)

이 인스턴스가 지정한 EntityKey와 같은지 여부를 나타내는 값을 반환합니다.

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

GetEntitySet(MetadataWorkspace)

지정된 메타데이터 작업 영역에서 이 엔터티 키에 대한 엔터티 집합을 가져옵니다.

GetHashCode()

현재 EntityKey 개체의 해시 함수로 사용됩니다. GetHashCode()는 해시 알고리즘 및 해시 테이블과 같은 데이터 구조에 적합합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

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

현재 Object의 단순 복사본을 만듭니다.

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

EntityKey를 역직렬화하는 데 사용되는 도우미 메서드입니다.

OnDeserializing(StreamingContext)

EntityKey를 역직렬화하는 데 사용되는 도우미 메서드입니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

연산자

Equality(EntityKey, EntityKey)

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

Inequality(EntityKey, EntityKey)

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

적용 대상