DynamicProperties and ManyValueAssociations

Now, that DynamicProperties supports ManyValueAssociations, it would also be nice to work with them in an abstract way.

For my example, I know both classes that should be mapped, by their TClass.
As far as I know, there is no way to build a generic List using TClass variable.

How could I solve this?

If I understand correctly what you want, that is not possible. You can't create an Aurelius mapping to a class that simply doesn't exist. As the result the of many-valued associations are TList<T>, such class must exist and you need its type info, so Aurelius can handle it, instantiate it, etc.

for example:

procedure CreateDynamicProps(aClass, aChildClass: TClass; aSetup: TMappingSetup);
  hProps, hChildProps: TDynamicPropertyList;
  hProps := aSetup.DynamicProps[aClass];
  hChildProps  := aSetup.DynamicProps[aChildClass];

  // Association works:
  hProp := TDynamicProperty.Create(csProps, 'AssocData', aChildClass.ClassInfo);
  hProps .Add(hProp);
  hProp.AddAssociation(Association.Create([], CascadeTypeAllRemoveOrphan));
  hProp.AddColumn(JoinColumn.Create('AssocID', []));

  // ManyValued Association does not work:
  hProp := TDynamicProperty.Create(csProps, 'MVAssocData', TList<aClass.ClassInfo>);
  hProp.AddAssociation(ManyValuedAssociation.Create([], CascadeTypeAllRemoveOrphan, 'AssocData'));

So I know the Class and it exists.

This is the problem. You have to have the TList<T> class. You can't create a class of TList<T> dynamically.

Well, I know, that this is the point.

I think I could make a workaround by creating aliases for each of my entityclasses, register them and select them through the registered classtypes.

like that

TEntityList = TList<TEntity>;
RegisterList(TEntity, TEntityList);
hEntityListType := Register.Find(aClass);
hProp := TDynamicProperty.Create(csProps, 'MVAssocData', hEntityListType);

Maybe that would work :wink:

1 Like