EntityKey 생성자

정의

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

오버로드

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

적용 대상