ObjectStateManager 클래스

정의

엔터티 형식 인스턴스 및 관계 인스턴스에 대한 개체 상태 및 ID 관리를 유지 관리합니다.

public ref class ObjectStateManager
public class ObjectStateManager
type ObjectStateManager = class
Public Class ObjectStateManager
상속
ObjectStateManager

예제

다음 예제에서는 원본 ObjectContextObjectStateManager 가져오고 상태 관리자를 사용하여 컨텍스트의 개체에 액세스합니다.

int orderId = 43680;

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    ObjectStateManager objectStateManager = context.ObjectStateManager;
    ObjectStateEntry stateEntry = null;

    var order = (from o in context.SalesOrderHeaders
                 where o.SalesOrderID == orderId
                 select o).First();

    // Attempts to retrieve ObjectStateEntry for the given EntityKey.
    bool isPresent = objectStateManager.TryGetObjectStateEntry(((IEntityWithKey)order).EntityKey, out stateEntry);
    if (isPresent)
    {
        Console.WriteLine("The entity was found");
    }
}

다음 예제에서는 반환 ObjectStateManagerTryGetObjectStateEntry(EntityKey, ObjectStateEntry) 메서드를 사용하여 엔터티 키를 기반으로 개체를 가져옵니다.

private static void ApplyItemUpdates(SalesOrderDetail originalItem,
    SalesOrderDetail updatedItem)
{
    using (AdventureWorksEntities context =
        new AdventureWorksEntities())
    {
        context.SalesOrderDetails.Attach(updatedItem);
        // Check if the ID is 0, if it is the item is new.
        // In this case we need to chage the state to Added.
        if (updatedItem.SalesOrderDetailID == 0)
        {
            // Because the ID is generated by the database we do not need to
            // set updatedItem.SalesOrderDetailID.
            context.ObjectStateManager.ChangeObjectState(updatedItem, System.Data.EntityState.Added);
        }
        else
        {
            // If the SalesOrderDetailID is not 0, then the item is not new
            // and needs to be updated. Because we already added the
            // updated object to the context we need to apply the original values.
            // If we attached originalItem to the context
            // we would need to apply the current values:
            // context.ApplyCurrentValues("SalesOrderDetails", updatedItem);
            // Applying current or original values, changes the state
            // of the attached object to Modified.
            context.ApplyOriginalValues("SalesOrderDetails", originalItem);
        }
        context.SaveChanges();
    }
}

설명

ObjectStateManager 는 쿼리 결과를 추적하고 여러 겹치는 쿼리 결과를 병합하는 논리를 제공합니다. 또한 사용자가 개체를 삽입, 삭제 또는 수정할 때 메모리 내 변경 내용 추적을 수행하고 업데이트에 대한 변경 집합을 제공합니다. 이 변경 집합은 변경 프로세서에서 수정을 유지하는 데 사용됩니다.

이 클래스는 일반적으로 애플리케이션에서 직접 사용되지 않고 사용됩니다 ObjectContext .

생성자

Name Description
ObjectStateManager(MetadataWorkspace)

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

속성

Name Description
MetadataWorkspace

MetadataWorkspace 이 상태 관리자와 연결된 값을 가져옵니다.

메서드

Name Description
ChangeObjectState(Object, EntityState)

특정 개체의 ObjectStateEntry 상태를 지정된 개체로 변경합니다 entityState.

ChangeRelationshipState(Object, Object, String, EntityState)

두 개의 관련 개체와 탐색 속성의 이름을 기반으로 지정된 두 엔터티 개체 간의 관계 상태를 변경합니다.

ChangeRelationshipState(Object, Object, String, String, EntityState)

두 개의 관련 개체와 관계의 속성에 따라 지정된 두 엔터티 개체 간의 관계 상태를 변경합니다.

ChangeRelationshipState<TEntity>(TEntity, Object, Expression<Func<TEntity,Object>>, EntityState)

두 개의 관련 개체와 탐색 속성을 정의하는 LINQ 식을 기반으로 지정된 두 엔터티 개체 간의 관계 상태를 변경합니다.

Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetObjectStateEntries(EntityState)

지정된 상태의 ObjectStateEntry 개체 또는 관계에 대한 개체 컬렉션을 반환합니다.

GetObjectStateEntry(EntityKey)

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

GetObjectStateEntry(Object)

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

GetRelationshipManager(Object)

RelationshipManager 지정된 개체에 사용되는 값을 반환합니다.

GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
TryGetObjectStateEntry(EntityKey, ObjectStateEntry)

지정된 EntityKey개체 또는 관계에 해당하는 개체를 검색 ObjectStateEntry 하려고 시도합니다.

TryGetObjectStateEntry(Object, ObjectStateEntry)

지정된 에 해당하는 ObjectStateEntry 값을 검색하려고 시도합니다 Object.

TryGetRelationshipManager(Object, RelationshipManager)

RelationshipManager 지정된 개체에 사용되는 값을 반환합니다.

이벤트

Name Description
ObjectStateManagerChanged

엔터티가 상태 관리자에 추가되거나 제거될 때 발생합니다.

적용 대상