Richard Banks - 2004-08-03

Hi everyone,

It is now possible to map properties of classes contained with a persistent class without actually mapping the contained class itself.

Since .NET structures themselves cannot be mapped (as they are value types and updating member properties is difficult)  you can do something like the following:

Public Class SomeStruct
  Private _partA As String
  Private _parent As AToMSFramework.CPersistentObject

  Public Property PartA() As String
    Get
      Return _partA
    End Get
    Set(ByVal Value As String)
      _partA = Value
      If Not _parent Is Nothing Then
        _parent.SetDirtyFlag()
      End If
    End Set
  End Property

  Friend Property Parent() As AToMSFramework.CPersistentObject
    Get
      Return _parent
    End Get
    Set(ByVal Value As AToMSFramework.CPersistentObject)
      _parent = Value
    End Set
  End Property
End Class

-------------
Public Class Class1
  Inherits CPersistentObject

  Private _ss As SomeStruct

  Public Property Struct1() As SomeStruct
    Get
      Return _ss
    End Get
    Set(ByVal Value As SomeStruct)
      _ss = Value
      SetDirtyFlag()
    End Set
  End Property

  Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject
    Return New Class1
  End Function

  Public Overrides Function IsValid() As Boolean
    Return True
  End Function

  Public Sub New()
    _ss = New SomeStruct
    _ss.Parent = Me
  End Sub
End Class
-----------
<class name="Class1" table="xx" database="db1">
  <attribute name="OIDValue" column="oid" key="primary"/>
  <attribute name="Struct1.PartA" column="partA" />
</class>
--------

In your code you can now do

    Dim c1 As New Class1
    c1.Struct1.PartA = "AA"
    c1.Save()

or

    c1.OIDValue = "000000420001"
    c1.Retrieve(c1)
    Debug.WriteLine(c1.Struct1.PartA)

and everything will work correctly.

The code is currently in CVS and will be included in the next release.

- Richard.