Chili.Opf3 Send comments on this topic.
SetObjectState Method
See Also  Example
Chili.Opf3 Namespace > ObjectContext Class : SetObjectState Method




obj
Persistent objects that ObjectStates is changed.
objectState
ObjectStates that is set for the given persistent object.
Sets the state of the persistent object to the given ObjectStates.

Syntax

Visual Basic (Declaration) 
Public Function SetObjectState( _
   ByVal obj As Object, _
   ByVal objectState As ObjectStates _
) As Boolean
Visual Basic (Usage)Copy Code
Dim instance As ObjectContext
Dim obj As Object
Dim objectState As ObjectStates
Dim value As Boolean
 
value = instance.SetObjectState(obj, objectState)
C# 
public bool SetObjectState( 
   object obj,
   ObjectStates objectState
)
Managed Extensions for C++ 
public: bool SetObjectState( 
   Object* obj,
   ObjectStates objectState
) 
C++/CLI 
public:
bool SetObjectState( 
   Object^ obj,
   ObjectStates objectState
) 

Parameters

obj
Persistent objects that ObjectStates is changed.
objectState
ObjectStates that is set for the given persistent object.

Example

The following example changes the state of an object.
C#Copy Code
// Load the object from the storage. 
 User user1 = context.GetObject<User>("Id = {0}", "1"); 
  
 // Create a new user object. 
 User user2 = new User(); 
 // Copy all properties of the first user object to the second. 
 user2.Name = user1.Name; 
 // ... Other properties. 
  
 // Set the state of the object as inserted. This means that 
 // the framework will do an update the next time when saving the  
 // object. 
 context.SetObjectState<User>(user2, ObjectStates.Inserted); 
  
 // Change the object. 
 user2.Name = "new Name"; 
 // Persist the changes. 
 context.PersistChanges(user2); 
    

Remarks

This routine allows to update an object in the storage without having it loaded. It's important that all properties that are persisted have the same values as the fields of the record in the storage. If they vary the IConcurrencyManager will throw an exception during the next save process.

You could use this routine to avoid implementing the ISelfContainingObject interface when loading a persistent object with one ObjectContext and saving it with another (that works on the same storage).

Requirements

Platforms: Windows 2000, Windows XP family, Windows Server 2003 family, Windows Vista family

See Also