views:

15

answers:

0

I just wanted to see the data (which peroperties getting changed) in the ObjectStateManager while I am updating data in my POCO class:-

 using (POCOObjectContext context = new POCOObjectContext())
            {
                SeeDataInObjectStateManager(context.ObjectStateManager);
                Contact contactObj = context.Contacts.Single<Contact>(contact => contact.FirstName == "Ricky");
                contactObj.LastName = "Krishnan";
                SeeDataInObjectStateManager(context.ObjectStateManager);
                context.SaveChanges();

            }

Following is the method which is getting called:-

static void SeeDataInObjectStateManager(ObjectStateManager manager)
        {
            EntityState[] values = (EntityState[])Enum.GetValues(typeof(EntityState));
            foreach (var entityState in values)
            {
               if (entityState == EntityState.Detached) continue;
               foreach (ObjectStateEntry  entry in manager.GetObjectStateEntries(entityState))
                {
                    foreach (var item in entry.GetModifiedProperties())
                    {
                        Console.WriteLine("Item " + string.Join("-", item));
                    }
                }
            }
        }

For some reason, entry.GetModifiedProperties() also does not return any data, although I am changing one of the properties. Am I missing anything?