T
Chili.Opf3 Send comments on this topic.
Generic ObjectSet Class
See Also  Members   Example 
Chili.Opf3 Namespace : Generic ObjectSet Class




Represents an in-memory cache of persistent objects.

Syntax

Visual Basic (Declaration) 
Public Class ObjectSet(Of T) 
   Implements ICustomPersister 
Visual Basic (Usage)Copy Code
Dim instance As ObjectSet(Of T)
C# 
public class ObjectSet<T> : ICustomPersister  
Managed Extensions for C++ 
public __gc class ObjectSet<T> : public ICustomPersister  
C++/CLI 
generic<typename T>
public ref class ObjectSet : public ICustomPersister  

Type Parameters

T

Example

The following example shows how to use the ObjectSet in an application.
C#Copy Code
            [Persistent("USER")] 
public class User 

    private string _name; 
 
    [Field("NAME")] 
    public string Name 
    { 
        get { return _name; } 
        set { _name = value; } 
    } 
 
    // ... Other properties and fields. 

 
// ... Other code 
 
// Loads an ObjectSet of User from the storage and sorts the result descending. 
ObjectSet<User> objectSet = context.GetObjectSet<User> 
    ("UserName like {0} SortBy UserName Desc", "%mit%"); 
 
if (objectSet.Count > 3) 

    // Change a property of the first element in the 
    // ObjectSet. 
    User user = objectSet[0]; 
    user.Name = "new Name"; 
 
    // Mark the second and thirth element for deletion. 
    objectSet.Remove(objectSet[1]); 
    // When marking the thirth element we use 1 as index 
    // since the second object has been already moved 
    // to the RemovedList. 
    objectSet.RemoveAt(1); 
 
    // Restore the first element in the RemovedList. 
    user = objectSet.RemovedList[0]; 
    objectSet.RemovedList.RemoveAt(0); 
    objectSet.Add(user); 

 
// Save the changes. 
context.StartTransaction(); 
context.PersistChanges<User>(objectSet); 
context.Commit(); 
    

Remarks

The ObjectSet, which is an in-memory cache of persistent objects retrieved from the storage, is a major component of the framework. It consists of a collection that contains objects of the type specified as generic argument.

The class contains also a list of removed items. Use Remove or RemoveAt to mark objects for deletion. They are moved to the RemovedList and deleted the next time the ObjectSet is saved. Objects on the RemovedList can also be moved back to the ObjectSet (or removed from the RemovedList) if you won't delete them.

The changes on the ObjectSet are saved using the PersistChanges method of the ObjectContext.

Inheritance Hierarchy

System.Object
   Chili.Opf3.ObjectSet

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