EntityKey EntityKey EntityKey EntityKey Constructors

定義

オーバーロード

EntityKey() EntityKey() EntityKey()

EntityKey クラスの新しいインスタンスを初期化します。Initializes a new instance of the EntityKey class.

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

エンティティ セット名および特定のエンティティ キーのペアを使用して、EntityKey クラスの新しいインスタンスを初期化します。Initializes a new instance of the EntityKey class with an entity set name and specific entity key pair.

EntityKey() EntityKey() EntityKey()

EntityKey クラスの新しいインスタンスを初期化します。Initializes a new instance of the EntityKey class.

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

EntityKey(String, IEnumerable<KeyValuePair<String,Object>>) EntityKey(String, IEnumerable<KeyValuePair<String,Object>>) EntityKey(String, IEnumerable<KeyValuePair<String,Object>>) 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.

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 String String

エンティティ コンテナー名で修飾されたエンティティ セット名を表す StringA String that is the entity set name qualified by the entity container name.

entityKeyValues
IEnumerable<KeyValuePair<String,Object>>

ジェネリック型の KeyValuePair コレクション。A generic KeyValuePair collection.

キー/値の各ペアでは、プロパティ名がキー、そのプロパティの値が値となっています。Each key/value pair has a property name as the key and the value of that property as the value. EntityKey の一部であるプロパティごとに、1 つのペアが必要です。There should be one pair for each property that is part of the EntityKey. キー/値のペアの順序は重要ではありませんが、各キー プロパティが含まれている必要があります。The order of the key/value pairs is not important, but each key property should be included. プロパティ名は、エンティティ型の名前やスキーマ名で修飾されていない単純な名前です。The property names are simple names that are not qualified with an entity type name or the schema name.

この例がに基づいて、 AdventureWorks Sales Modelします。This example is based on the AdventureWorks Sales Model. 例を作成および使用方法を示します、EntityKeyします。The example shows you how to create and use an 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);
    }
}
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(String, IEnumerable<EntityKeyMember>) EntityKey(String, IEnumerable<EntityKeyMember>) EntityKey(String, IEnumerable<EntityKeyMember>) 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.

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 String String

エンティティ コンテナー名で修飾されたエンティティ セット名を表す StringA String that is the entity set name qualified by the entity container name.

entityKeyValues
IEnumerable<EntityKeyMember>

キーの初期化に使用される EntityKeyMember オブジェクトの IEnumerable<T> コレクション。An IEnumerable<T> collection of EntityKeyMember objects with which to initialize the key.

EntityKey(String, String, Object) EntityKey(String, String, Object) EntityKey(String, String, Object) EntityKey(String, String, Object)

エンティティ セット名および特定のエンティティ キーのペアを使用して、EntityKey クラスの新しいインスタンスを初期化します。Initializes a new instance of the EntityKey class with an entity set name and specific entity key pair.

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 String String

エンティティ コンテナー名で修飾されたエンティティ セット名を表す StringA String that is the entity set name qualified by the entity container name.

keyName
String String String String

キーの名前を表す StringA String that is the name of the key.

keyValue
Object Object Object Object

キーの値を表す ObjectAn Object that is the key value.

この例がに基づいて、 AdventureWorks Sales Modelします。This example is based on the AdventureWorks Sales Model. 例を作成および使用方法を示します、EntityKeyします。The example shows you how to create and use an 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);
    }
}
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

適用対象