EntityKey 생성자

정의

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

오버로드

Name Description
EntityKey()

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

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

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

EntityKey(String, IEnumerable<EntityKeyMember>)

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

EntityKey(String, String, Object)

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

EntityKey()

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

public:
 EntityKey();
public EntityKey();
Public Sub New ()

적용 대상

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

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

public:
 EntityKey(System::String ^ qualifiedEntitySetName, System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<System::String ^, System::Object ^>> ^ entityKeyValues);
public EntityKey(string qualifiedEntitySetName, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string,object>> entityKeyValues);
new System.Data.EntityKey : string * seq<System.Collections.Generic.KeyValuePair<string, obj>> -> System.Data.EntityKey
Public Sub New (qualifiedEntitySetName As String, entityKeyValues As IEnumerable(Of KeyValuePair(Of String, Object)))

매개 변수

qualifiedEntitySetName
String

String 엔터티 컨테이너 이름으로 정규화된 엔터티 집합 이름입니다.

entityKeyValues
IEnumerable<KeyValuePair<String,Object>>

제네릭 KeyValuePair 컬렉션입니다.

각 키/값 쌍에는 속성 이름이 키로, 해당 속성 값이 값으로 지정됩니다. 의 일부인 각 속성에 대해 한 쌍이 EntityKey있어야 합니다. 키/값 쌍의 순서는 중요하지 않지만 각 키 속성을 포함해야 합니다. 속성 이름은 엔터티 형식 이름 또는 스키마 이름으로 정규화되지 않은 단순 이름입니다.

예제

이 예제에서는 EntityKey.

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(String, IEnumerable<EntityKeyMember>)

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

public:
 EntityKey(System::String ^ qualifiedEntitySetName, System::Collections::Generic::IEnumerable<System::Data::EntityKeyMember ^> ^ entityKeyValues);
public EntityKey(string qualifiedEntitySetName, System.Collections.Generic.IEnumerable<System.Data.EntityKeyMember> entityKeyValues);
new System.Data.EntityKey : string * seq<System.Data.EntityKeyMember> -> System.Data.EntityKey
Public Sub New (qualifiedEntitySetName As String, entityKeyValues As IEnumerable(Of EntityKeyMember))

매개 변수

qualifiedEntitySetName
String

String 엔터티 컨테이너 이름으로 정규화된 엔터티 집합 이름입니다.

entityKeyValues
IEnumerable<EntityKeyMember>

IEnumerable<T> 키를 초기화할 개체의 EntityKeyMember 컬렉션입니다.

적용 대상

EntityKey(String, String, Object)

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

public:
 EntityKey(System::String ^ qualifiedEntitySetName, System::String ^ keyName, System::Object ^ keyValue);
public EntityKey(string qualifiedEntitySetName, string keyName, object keyValue);
new System.Data.EntityKey : string * string * obj -> System.Data.EntityKey
Public Sub New (qualifiedEntitySetName As String, keyName As String, keyValue As Object)

매개 변수

qualifiedEntitySetName
String

String 엔터티 컨테이너 이름으로 정규화된 엔터티 집합 이름입니다.

keyName
String

String 키의 이름입니다.

keyValue
Object

Object 키 값입니다.

예제

이 예제에서는 EntityKey.

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);
    }
}

적용 대상