Ads 468x60px

Sunday, March 11, 2012

XAF : Implement One-to-Many Relationship

The following snippet of code present One-to-Many Relationship between Department and Contact business classes, in which Department object has many Contacts.
To implement the "One" part of the Department-Contacts relationship, decorate the Contact class Department property with the Association attribute.


   1:  <DefaultClassOptions()> _
   2:  Public Class Contact
   3:      Inherits Person
   4:      '...
   5:      Private fDepartment As Department
   6:      <Association("Department-Contacts", GetType(Department))> _
   7:      Public Property Department() As Department
   8:          Get
   9:              Return fDepartment
  10:          End Get
  11:          Set(ByVal value As Department)
  12:              SetPropertyValue("Department", fDepartment, value)
  13:          End Set
  14:      End Property
  15:      '...
  16:  End Class
  17:   
  18:   

To implement the "Many" part of the Department-Contacts relationship, add the Contacts property to the Department class and decorate this property with the Association attribute.

   1:  Public Class Department
   2:      Inherits BaseObject
   3:      '...
   4:      <Association("Department-Contacts", GetType(Contact))> _
   5:      Public ReadOnly Property Contacts() As XPCollection
   6:          Get
   7:              Return GetCollection("Contacts")
   8:          End Get
   9:      End Property
  10:  End Class

With the code above, necessary intermediate tables and relationships will be generated automatically.


[eXpressApp Framework]

1 comment:

  1. I wasn't going to excel as an athlete...not sure if that was disappointing to my dad but I never saw that once. They always encouraged me to pursue music as it was clear that was where I was gifted.
    http://www.goodlifeforever.com/2015/09/how-to-attract-man-12-easy-method.html

    ReplyDelete