Chili.Opf3 Send comments on this topic.
RelationAttribute Class
See Also  Members   Example 
Chili.Opf3.Relations Namespace : RelationAttribute Class




This attribute is used to specify a relation between two or more persistent objects.

Syntax

Visual Basic (Declaration) 
Public NotInheritable Class RelationAttribute 
   Inherits Attribute
Visual Basic (Usage)Copy Code
Dim instance As RelationAttribute
C# 
public sealed class RelationAttribute : Attribute 
Managed Extensions for C++ 
public __gc __sealed class RelationAttribute : public Attribute 
C++/CLI 
public ref class RelationAttribute sealed : public Attribute 

Example

The following example shows the usage of the RelationAttribute in combination with a ObjectSetHolder . The following example shows the usage of the RelationAttribute with multiple columns as keys.
C#Copy Code
             [Persistent("USER", PoolSize = 50)] 
public class User 

       // ... Other properties and code. 
 
       // The class contains an ObjectSetHolder and a RelationAttribute 
       // that specifies the relation between the parent object and the  
       // related objects. 
       [Relation("Id", "UserId")] 
       private ObjectSetHolder<Call> _calls = new ObjectSetHolder<Call>(); 
 
       // This relation specifies a many-to-many relation. Each user has different rights 
       // and each right has different user. 
       [Relation("Id = UserId", WeakPersistent = typeof(UserRight),  
           WeakRelations = "RightId = Id", Name = "Rights"] 
       private ObjectSetHolder<Right> _rights = new ObjectSetHolder<Right>(); 
    
       public ObjectSet<Call> Calls 
       { 
           get { return _calls.InnerObject; } 
           set { _calls.InnerObject = value; } 
       } 
 
       [Field("ID", Identifier = true, AllowDBNull = false)] 
       public string Id 
       { 
           get { return _id; } 
           set { _id = value; } 
       } 
        
       // ... Other properties and code. 

 
[Persistent("CALLS", PoolSize = 20)] 
public class Call 

       // ... Other properties and code. 
 
       [Field("USER_ID")] 
       public string UserId 
       { 
           get { return _userId; } 
           set { _userId = value; } 
       } 
 
       // ... Other properties and code. 

 
[Persistent("USER_RIGHTS")] 
                 public class UserRight 

       // ... Other properties and code. 
 
       [Field("USER_ID", AllowDBNull = false, Identifier = true)] 
       public string UserId 
       { 
           get { return _userId; } 
           set { _userId = value; } 
       } 
        
       [Field("RIGHT_ID", AllowDBNull = false, Identifier = true)] 
       public string RightId 
       { 
           get { return _rightId; } 
           set { _rightId = value; } 
       } 

 
[Persistent("RIGHTS")] 
public class Right 

       // ... Other properties and code. 
                         
       [Field("ID", AllowDBNull = false, Identifier = true)] 
       public string Id 
       { 
           get { return _rightId; } 
           set { _rightId = value; } 
       } 
        
       [Field("NAME", AllowDBNull = false)] 
       public string Name 
       { 
           get { return _name; } 
           set { _name = value; } 
       } 

   
C#Copy Code
             [Persistent("USER", PoolSize = 50)] 
public class User 

       // ... Other properties and code. 
 
       // The class contains an ObjectSetHolder and a RelationAttribute 
       // that specifies the relation between the parent object and the  
       // related objects. Multiple columns are separated by a semi colon (;). 
       // The relation is also given a name. 
       [RelationAttribute("Id1 = UserId1; Id2 = UserId2", Name = "Calls")] 
       private ObjectSetHolder<Call> _calls = new ObjectSetHolder<Call>(); 
    
       public ObjectSet<Call> Calls 
       { 
           get { return _calls.InnerObject; } 
           set { _calls.InnerObject = value; } 
       } 
 
       [Field("ID1", Identifier = true, AllowDBNull = false)] 
       public string Id1 
       { 
           get { return _id1; } 
           set { _id1 = value; } 
       } 
        
       [Field("ID2", Identifier = true, AllowDBNull = false)] 
       public string Id2 
       { 
           get { return _id2; } 
           set { _id2 = value; } 
       } 
 
       // ... Other properties and code. 

                    

Remarks

This attribute is used on ObjectHolder classes (ObjectHolder, ObjectListHolder, ObjectSetHolder) to specify the relation between the connected (related) persistent objects and the parent object (the persistent object that contains the attribute and the ObjectHolder class). The attribute supports one-to-one, one-to-many and many-to-many relations.

To use the attribute you have to specify the ParentMember (which is a property or field of the parent object) and the ChildMember (which is one property or field of the child object). Usually one of the object member (property or field) is marked as foreign key in the storage.

Inheritance Hierarchy

System.Object
   System.Attribute
      Chili.Opf3.Relations.RelationAttribute

Requirements

Namespace: Chili.Opf3.Relations

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