ObjectStateManager.GetObjectStateEntry 메서드

정의

ObjectStateEntry 특정 개체 또는 관계 항목에 대한 값을 반환합니다.

오버로드

Name Description
GetObjectStateEntry(EntityKey)

지정된 키를 가진 ObjectStateEntry 개체 또는 관계 항목에 대한 값을 반환합니다.

GetObjectStateEntry(Object)

ObjectStateEntry 지정된 개체에 대한 값을 반환합니다.

GetObjectStateEntry(EntityKey)

지정된 키를 가진 ObjectStateEntry 개체 또는 관계 항목에 대한 값을 반환합니다.

public:
 System::Data::Objects::ObjectStateEntry ^ GetObjectStateEntry(System::Data::EntityKey ^ key);
public System.Data.Objects.ObjectStateEntry GetObjectStateEntry(System.Data.EntityKey key);
member this.GetObjectStateEntry : System.Data.EntityKey -> System.Data.Objects.ObjectStateEntry
Public Function GetObjectStateEntry (key As EntityKey) As ObjectStateEntry

매개 변수

반품

지정된 EntityKey.에 해당하는 ObjectStateEntry 항목입니다.

예외

시기 key 입니다.null

상태 관리자에서 지정된 key 값을 찾을 수 없는 경우

지정된 EntityKeyObjectStateManager엔터티가 없습니다.

예제

이 예제에서는 지정된 ObjectStateEntry 에 대한 EntityKeyObjectStateManager값을 가져옵니다. 그런 다음 속성의 SalesOrderHeader.PurchaseOrderNumber 현재 값을 가져오고, 속성의 값을 변경하고, 수정된 속성 컬렉션을 열거합니다.

// Specify the order to update.
int orderId = 43680;

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    try
    {
        var order = (from o in context.SalesOrderHeaders
                     where o.SalesOrderID == orderId
                     select o).First();

        // Change the status of an existing order.
        order.Status = 1;

        // Delete the first item in the order.
        context.DeleteObject(order.SalesOrderDetails.First());

        // 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 = 0,
            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);

        // Get the ObjectStateEntry for the order.
        ObjectStateEntry stateEntry =
            context.ObjectStateManager
            .GetObjectStateEntry(order);
        Console.WriteLine("State before SaveChanges() is called: {0}",
            stateEntry.State.ToString());

        // Save changes in the object context to the database.
        int changes = context.SaveChanges();

        Console.WriteLine("State after SaveChanges() is called: {0}",
            stateEntry.State.ToString());

        Console.WriteLine(changes.ToString() + " changes saved!");
        Console.WriteLine("Updated item for order ID: "
            + order.SalesOrderID.ToString());

        // Iterate through the collection of SalesOrderDetail items.
        foreach (SalesOrderDetail item in order.SalesOrderDetails)
        {
            Console.WriteLine("Item ID: "
                + item.SalesOrderDetailID.ToString() + "  Product: "
                + item.ProductID.ToString() + "  Quantity: "
                + item.OrderQty.ToString());
        }
    }
    catch (UpdateException ex)
    {
        Console.WriteLine(ex.ToString());
    }
}

설명

메서드에서 TryGetObjectStateEntry(EntityKey, ObjectStateEntry) 발생된 개체를 ObjectStateEntry 처리할 필요 없이 메서드를 사용하여 개체를 InvalidOperationException 반환합니다 GetObjectStateEntry(EntityKey) .

적용 대상

GetObjectStateEntry(Object)

ObjectStateEntry 지정된 개체에 대한 값을 반환합니다.

public:
 System::Data::Objects::ObjectStateEntry ^ GetObjectStateEntry(System::Object ^ entity);
public System.Data.Objects.ObjectStateEntry GetObjectStateEntry(object entity);
member this.GetObjectStateEntry : obj -> System.Data.Objects.ObjectStateEntry
Public Function GetObjectStateEntry (entity As Object) As ObjectStateEntry

매개 변수

entity
Object

Object 검색된 ObjectStateEntry 개체가 속한 값입니다.

반품

지정된 Object.에 해당하는 ObjectStateEntry 항목입니다.

예외

에 지정된 Object 엔터티가 ObjectStateManager없습니다.

설명

메서드에서 TryGetObjectStateEntry(Object, ObjectStateEntry) 발생된 개체를 ObjectStateEntry 처리할 필요 없이 메서드를 사용하여 개체를 InvalidOperationException 반환합니다 GetObjectStateEntry(Object) .

적용 대상