Chili.Opf3 Send comments on this topic.
FetchingStorageRecord Event
See Also  Example
Chili.Opf3 Namespace > Generic ObjectReader 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 ObjectReader(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
ObjectReader<User> reader = context.GetObjectReader<User>(); 
// Register the event. 
reader.FetchingStorageRecord += new PersistentTypeSelector(MySelection); 
 
// Loop trough all items. 
foreach (User user in reader) 

    if (user.GetType() == typeof(User1)) 
        Console.WriteLine("User1 found."); 
    else 
        Console.WriteLine("User found."); 

 
// ... 
 
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); 
}

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