T
Chili.Opf3 Send comments on this topic.
Generic PersistChanges(T) Method
See Also  Example
Chili.Opf3 Namespace > ObjectContext Class > PersistChanges Method : Generic PersistChanges(T) Method




obj
Persistent object, ObjectSet or class that implements the ICustomPersister interface that is persisted.
Persists the changes on a single persistent object, an ObjectSet and a class that implements the ICustomPersister interface.

Syntax

Visual Basic (Declaration) 
Overloads Public Overridable Sub PersistChanges(Of T)( _
   ByVal obj As T _
) 
Visual Basic (Usage)Copy Code
Dim instance As ObjectContext
Dim obj As T
 
instance.PersistChanges(Of T)(obj)
C# 
public virtual void PersistChanges<T>( 
   T obj
)
Managed Extensions for C++ 
public: virtual void PersistChanges<T>( 
   T obj
) 
C++/CLI 
public:
virtual void PersistChangesgeneric<typename T>
( 
   T obj
) 

Parameters

obj
Persistent object, ObjectSet or class that implements the ICustomPersister interface that is persisted.

Type Parameters

T

Exceptions

ExceptionDescription
ConstraintExceptionA mandatory property of one persistent object returned Null.
ConcurrencyExceptionSomebody else changed the object in the storage while it has been in memory.
StorageExceptionIndicates a problem with the storage. All derived exception may also be thrown.

Example

The following example shows you how to persist a single persistent object.
C#Copy Code
// Creates a new ObjectContext that uses an MsSql Server as storage. 
ObjectContext context = new ObjectContext(new MsSqlStorage("sa", "",  
    "localhost", "application")); 
  
// ... Other code. 
  
// Get the first user matching the name. 
User user = context.GetObject<User>("Name like {0}", "%mith%"); 
  
// Changes the name property. 
user.Name = "new Name"; 
  
// Persists the user object. 
context.PersistChanges(user); 
    

Remarks

This routine persists the changes on one single persistent object, an ObjectSet and a class that implements the ICustomPersister interface. Some times you need to save only one single object in the storage. Use this routine if you have only one persistent object to be saved. Don't use this routine for lists of objects (except the ObjectSet) or non persistent objects (if they don't implement ICustomPersister).

Requirements

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

See Also