ObjectStateManager.GetObjectStateEntry 메서드

정의

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

오버로드

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

매개 변수

반환

지정된 ObjectStateEntry의 해당 EntityKey입니다.

예외

keynull일 경우

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

EntityKey에 지정된 ObjectStateManager의 엔터티가 없는 경우

예제

이 예제에서는 에서 지정된 EntityKey 에 대한 를 ObjectStateManager가져옵니다ObjectStateEntry. 그런 다음 속성의 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입니다.

반환

지정된 ObjectStateEntry의 해당 Object입니다.

예외

지정된 Object에 대한 엔터티가 ObjectStateManager에 없는 경우

설명

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

적용 대상