简体   繁体   中英

What is ObjectStateManager in EF4

I have heard that performance vise EF4 is more better than all it's previous version. So i was using EF4 in one of my project.

I need some detailed description on what is ObjectStateManager and how does it works. How does it perform update and what happens in background while processing.

Maintains the identity management and object state for entity type instances and relationship instances.

You can read this link who bring detail about class

http://msdn.microsoft.com/fr-fr/library/system.data.objects.objectstatemanager.aspx

the ObjectStateManager from the ObjectContext and uses the state manager to access an object in the context.

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

Here is a good answer I came across while searching for it a while ago

http://entityframeworktutorial.net/objectstatemanager.aspx#.UUhjRRwjzQU

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM