ObjectStateManager 클래스

정의

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

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

예제

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

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");
    }
}

다음 예제에서는 반환 ObjectStateManager 된 의 TryGetObjectStateEntry(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에서 사용됩니다.

생성자

ObjectStateManager(MetadataWorkspace)

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

속성

MetadataWorkspace

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

메서드

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)

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

TryGetObjectStateEntry(Object, ObjectStateEntry)

지정된 ObjectStateEntry에 대한 해당 Object를 검색하려고 시도합니다.

TryGetRelationshipManager(Object, RelationshipManager)

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

이벤트

ObjectStateManagerChanged

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

적용 대상