Chili.Opf3 Send comments on this topic.
FetchingStorageRecord Event
See Also  Example
Chili.Opf3.Relations Namespace > Generic ObjectSetHolder Class : FetchingStorageRecord Event




Event is fired before the data from the storage is used to populate an object.

Syntax

Visual Basic (Declaration) 
Public Event FetchingStorageRecord() As PersistentTypeSelector
Visual Basic (Usage)Copy Code
Dim instance As ObjectSetHolder(Of T)
Dim handler As PersistentTypeSelector
 
AddHandler instance.FetchingStorageRecord, handler
C# 
public event PersistentTypeSelector FetchingStorageRecord()
Managed Extensions for C++ 
public: __event PersistentTypeSelector* FetchingStorageRecord();
C++/CLI 
public:
event PersistentTypeSelector^ FetchingStorageRecord();

Event Data

The event handler receives an argument of type FetchingStorageRecordEventArgs containing data related to this event. The following FetchingStorageRecordEventArgs properties provide information specific to this event.

PropertyDescription
DataRecord Returns the current IDataRecord representing the current row or item of the storage.
Ignore Specifies whether to ignore the current row or item of the storage. Ignoring the current means that no persistent object is created and the framework tries to process the next item.
Type Specifies the type of the persistent object that is created.

Example

The following example introduces to the use of the FecthingStorageRecord event.
C#Copy Code
             [Persistent("USER", PoolSize = 50)] 
public class User 

                    // The class contains an ObjectSetHolder and a RelationAttribute 
                    // that specifies the relation between the parent object and the  
                    // related objects. It demonstrates also how to use a condition to  
                    // delimit the items in the list and to sort the result. 
                    [Relation("Id", "UserId")] 
                    private ObjectSetHolder<Call> _calls =  
                        new ObjectSetHolder<Call>("Duration < {0} SortBy Duration Asc", "50"); 
                 
    public User() 
    { 
        _calls.FetchingStorageRecord += PersistentTypeSelector(MySelection); 
    } 
 
    private void MySelection(object sender, FetchingStorageRecordEventArgs e) 
    { 
       if (e.DataRecord["Type"] == "1") 
       { 
           // Switch the type of the persistent that is created to User1. 
                           e.Type = typeof(User1); 
       } 
       else if ((bool)e.DataRecord["Ignore"]) 
       { 
           // Tell the framework to ignore this item. 
           e.Ignore = true; 
       } 
       // Have a persistent of type User created. 
       e.Type = typeof(User); 
    } 
 
                    public ObjectSet<Call> Calls 
                    { 
                        get { return _calls.InnerObject; } 
                        set { _calls.InnerObject = value; } 
                    } 
                     
                    // ... Other properties and code. 

 
// ... 
 
ObjectSet<User> objectSet = context.GetObjectSet<User>(); 
foreach(User user in objectSet) 

    foreach(Call call in user.Calls) 
    { 
        if (call.GetType() == typeof(Call1)) 
            Console.WriteLine("Call1 found."); 
        else 
            Console.WriteLine("Call found."); 
    } 
}

Remarks

This event is fired before the data from the storage is used to populate an object. It allows the user to specify another type for the row (item) that is populated with the data. It allows also to have certain items ignored. This event can be used in certain scenarios of inheritance.

Requirements

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

See Also