EntityKey Oluşturucular

Tanım

EntityKey sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

Name Description
EntityKey()

EntityKey sınıfının yeni bir örneğini başlatır.

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

Varlık kümesi adı ve genel EntityKey bir koleksiyon ile sınıfının yeni bir örneğini KeyValuePair başlatır.

EntityKey(String, IEnumerable<EntityKeyMember>)

Bir varlık kümesi adı ve bir nesne koleksiyonu ile sınıfının yeni bir EntityKey örneğini IEnumerable<T>EntityKeyMember başlatır.

EntityKey(String, String, Object)

Bir varlık kümesi adı ve belirli bir varlık anahtar çifti ile sınıfının yeni bir örneğini EntityKey başlatır.

EntityKey()

EntityKey sınıfının yeni bir örneğini başlatır.

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

Şunlara uygulanır

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

Varlık kümesi adı ve genel EntityKey bir koleksiyon ile sınıfının yeni bir örneğini KeyValuePair başlatır.

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

Parametreler

qualifiedEntitySetName
String

String Varlık kapsayıcısı adı tarafından nitelenmiş varlık kümesi adı olan bir.

entityKeyValues
IEnumerable<KeyValuePair<String,Object>>

Genel KeyValuePair bir koleksiyon.

Her anahtar/değer çiftinin anahtar olarak bir özellik adı ve değer olarak bu özelliğin değeri vardır. Her özellik için öğesinin bir parçası EntityKeyolan bir çift olmalıdır. Anahtar/değer çiftlerinin sırası önemli değildir, ancak her anahtar özelliği dahil edilmelidir. Özellik adları, varlık türü adı veya şema adıyla nitelenmiş olmayan basit adlardır.

Örnekler

Bu örnekte bir oluşturma ve kullanma gösterilmektedir 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);
    }
}

Şunlara uygulanır

EntityKey(String, IEnumerable<EntityKeyMember>)

Bir varlık kümesi adı ve bir nesne koleksiyonu ile sınıfının yeni bir EntityKey örneğini IEnumerable<T>EntityKeyMember başlatır.

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

Parametreler

qualifiedEntitySetName
String

String Varlık kapsayıcısı adı tarafından nitelenmiş varlık kümesi adı olan bir.

entityKeyValues
IEnumerable<EntityKeyMember>

IEnumerable<T> Anahtarın EntityKeyMember başlatıldığı nesne koleksiyonu.

Şunlara uygulanır

EntityKey(String, String, Object)

Bir varlık kümesi adı ve belirli bir varlık anahtar çifti ile sınıfının yeni bir örneğini EntityKey başlatır.

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)

Parametreler

qualifiedEntitySetName
String

String Varlık kapsayıcısı adı tarafından nitelenmiş varlık kümesi adı olan bir.

keyName
String

String Anahtarın adı olan bir.

keyValue
Object

Object Anahtar değeri olan.

Örnekler

Bu örnekte bir oluşturma ve kullanma gösterilmektedir 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);
    }
}

Şunlara uygulanır