Chili.Opf3 Send comments on this topic.
PersistentTypeSelector Delegate
See Also  Example
Chili.Opf3 Namespace : PersistentTypeSelector Delegate




sender
The object who invoked the delegate.
e
An instance of the FetchingStorageRecordEventArgs class containing all necessary properties to change the type or have the current item ignored.
Allows to specify a method that is invoked each time before a persistent object is created.

Syntax

Visual Basic (Declaration) 
Public Delegate Sub PersistentTypeSelector( _
   ByVal sender As Object, _
   ByVal e As FetchingStorageRecordEventArgs _
) 
Visual Basic (Usage)Copy Code
Dim instance As New PersistentTypeSelector(AddressOf HandlerMethod)
C# 
public delegate void PersistentTypeSelector( 
   object sender,
   FetchingStorageRecordEventArgs e
)
Managed Extensions for C++ 
public: __gc __delegate void PersistentTypeSelector( 
   Object* sender,
   FetchingStorageRecordEventArgs* e
)
C++/CLI 
public delegate void PersistentTypeSelector( 
   Object^ sender,
   FetchingStorageRecordEventArgs^ e
)

Parameters

sender
The object who invoked the delegate.
e
An instance of the FetchingStorageRecordEventArgs class containing all necessary properties to change the type or have the current item ignored.

Example

The following sample shows the usage of this delegate in some methods of the ObjectContext.
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 ObjectSet with user matching the name and sorting them by name. 
ObjectSet<User> objectSet = context.GetObjectSet<User>(new PersistentTypeSelector(MySelection)); 
  
// Loop through all items and do something. 
foreach(User user in objectSet) 

    // Do something. 

 
// ... 
 
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; 
    } 
    else 
    { 
        // Have a persistent of type User created. 
        e.Type = typeof(User); 
    } 
}

Remarks

This delegate allows to specify a method that is invoked each time before a persistent object is created. The type of the persistent object to create may be changed or the current row (item) in the storage may be ignored by applying the Ignore property of the FetchingStorageRecordEventArgs class.

This delegate is very useful in inheritance chains. It allows you to specify an inherited type as type of the persistent object, by analyzing the fields of the current row (item) of the storage or by having some other algorithm that decides how which type of class to create.

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