public bool TryGetObjectStateEntry(EntityKey key, out ObjectStateEntry entry)
        {
            ChangeSet changeSet = _context.GetChangeSet();

              object entity = changeSet.Inserts.SingleOrDefault(x => key.Matches(x));
              if (entity != null)
              {
            entry = new ObjectStateEntry { EntityKey = key, Entity = entity, State = EntityState.Added };
            return true;
              }

              entity = changeSet.Updates.SingleOrDefault(x => key.Matches(x));
              if (entity != null)
              {
            entry = new ObjectStateEntry { EntityKey = key, Entity = entity, State = EntityState.Modified };
            return true;
              }

              entity = changeSet.Deletes.SingleOrDefault(x => key.Matches(x));
              if (entity != null)
              {
            entry = new ObjectStateEntry { EntityKey = key, Entity = entity, State = EntityState.Deleted };
            return true;
              }

              MetaType metaType = _context.Mapping.GetTable(key.EntityType).RowType;
              entity = _dataServices.GetCachedObject(metaType, key.PrimaryKeyValues);
              if (entity != null)
              {
            entry = new ObjectStateEntry { EntityKey = key, Entity = entity, State = EntityState.Unchanged };
            return true;
              }

              entry = null;
              return false;
        }
        public bool TryGetObjectStateEntry(object entity, out ObjectStateEntry entry)
        {
            Type entityType = entity.GetType();
              var primaryKeys = DataContextHelper.GetPrimaryKeys(entityType);
              EntityKey key = new EntityKey(entityType, primaryKeys.Select(x => new KeyValuePair<Property, object>(x, x.GetValue(entity))));
              ChangeSet changeSet = _context.GetChangeSet();

              if (changeSet.Inserts.Any(x => x == entity))
              {
            entry = new ObjectStateEntry { EntityKey = key, Entity = entity, State = EntityState.Added };
            return true;
              }

              if (changeSet.Updates.Any(x => x == entity))
              {
            entry = new ObjectStateEntry { EntityKey = key, Entity = entity, State = EntityState.Modified };
            return true;
              }

              if (changeSet.Deletes.Any(x => x == entity))
              {
            entry = new ObjectStateEntry { EntityKey = key, Entity = entity, State = EntityState.Deleted };
            return true;
              }

              MetaType metaType = _context.Mapping.GetTable(key.EntityType).RowType;
              if (_dataServices.IsCachedObject(metaType, entity))
              {
            entry = new ObjectStateEntry { EntityKey = key, Entity = entity, State = EntityState.Unchanged };
            return true;
              }

              entry = null;
              return false;
        }