Chili.Opf3 Send comments on this topic.
ICustomPersister Interface
See Also  Members   Example
Chili.Opf3 Namespace : ICustomPersister Interface




This interface is implemented by classes that want do their save and load in a special mode.

Syntax

Visual Basic (Declaration) 
Public Interface ICustomPersister 
Visual Basic (Usage)Copy Code
Dim instance As ICustomPersister
C# 
public interface ICustomPersister 
Managed Extensions for C++ 
public __gc __interface ICustomPersister 
C++/CLI 
public interface class ICustomPersister 

Example

The following example shows a sample implementation of the interface.
C#Copy Code
public class MyList<T> : ICustomPersister<T:gt; 

                    private IList<T> _removedList = new List<T>(); 
 
                    public void Load(ObjectContext context, IQuery query) 
                    { 
                        // Load all objects matching the query. 
                        using(ObjectReader<T> reader =  
                            context.GetObjectReader<T>(query)) 
                        { 
                            // Add all objects found to the list. 
                            foreach(T obj in reader) 
                                this.Add(obj); 
                        } 
                    } 
 
                    public void Persist(ObjectContext context, PersistDepths persistDepth, PersistingTrace trace) 
                    { 
                        foreach (T obj in this) 
                            context.PersistChanges<T>(obj, persistDepth); 
 
                        // Delete all objects in the RemovedList. 
                        foreach (T obj in _removedList) 
                        { 
                            context.MarkForDeletion(obj); 
                            context.PersistChanges<T>(obj, persistDepth); 
                        } 
                        _removedList.Clear(); 
                    } 
 
                    public void MoveToRemovedList(T obj) 
                    { 
                        this.Remove(obj); 
                        _removedList.Add(obj); 
                    } 
 
                    // ... Other properties and code. 
}

Remarks

A class that needs a special way to persist or to load its member from the storage has to implement this interface. It's recommended to use this interface only for complex classes, that means classes consisting of a few or a list of persistent objects. If the ObjectContext encounters a class that implements this interface the load process (or persist process) is directly passed to the class. The class can then do it's special way to load or persist the members. As argument is passed the ObjectContext that should be used to load (or persist) the changes on the objects.

Currently ObjectSet implements this interface to do the custom save process. ObjectSet uses this interface since it has to save all persistent objects in the main list and to delete all persistent objects in the RemovedList. Without implementing this interface the user would have to delete manually the objects in the RemovedList.

Requirements

Namespace: Chili.Opf3

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: Chili.Opf3 (in Chili.Opf3.dll)

See Also