Converting Entity in Inheritance

Is it possible to convert an Entity within Inheritance?

for example:

[Entity]
[DiscriminatorColumn('Type', TDiscriminatorType.dtString)]
TFiles = class
  FField1: string;
  FField2: string;
end;

[AbstractEntity]
TImages = class(TFiles)...

[Entity]
[DiscriminatorValue('JPEG')]
TJPEG = class(TImages )
  FField3: nullable<string>;

end;

[Entity]
[DiscriminatorValue('GIF')]
TGIF = class(TImages )
  FField4: nullable<string>;
end;

I have an TGIF -Instance and would need to change it to TJPEG.
It is possible by doing stuff like this:

hJPEG := ObjMan.Find<TJPEG>(1);
hGIF := TGIF.Create;
hGIF.ID = hJPEG.ID;
ObjMan.SaveOrUpdate(hGIF);

but at the end a lot of Informations are set to NULL, because internally the copy-Fields does not worry about parent classes.

I think FField1 and 2 could be "copied". Field3 and 4 could not, because they do not exist.

If it's not possible yet, can you imagine providing a new (generic) method in Explorer or Manager, solving this? Maybe something like this:

TObjectManager.Convert<T: TObject>(aEntity: TObject): T;

could be called like this for my example:

hGIF := ObjMan.Convert<TGIF>(hJPEG);

There is no way to do that with Aurelius and I don't think it's desired to do so. It's not trivial to simply convert one object from one class to another, and it doesn't make sense from OOP point of view.

You should do that outside Aurelius scope, by manually updating the discriminator column value and updating/clearing all the other needed table columns.

Well, I got your point, but it would help me a lot, for other things to, if your CopyFieldValues would start like this:

// >>>
//  Assert(FromObj.ClassType = ToObj.ClassType);
////  Assert((FromObj.ClassType = ToObj.ClassType) or (ToObj.InheritsFrom(FromObj.ClassType)));
//  Members := GetClassStateMembers(FromObj.ClassType, True, False);
  if not ToObj.InheritsFrom(FromObj.ClassType) then
  begin
    hClass := nil;

    var hEntType: TEntityType;
    hEntType := GetEntityType(FromObj);
    while Assigned(hEntType) do
      if not ToObj.InheritsFrom(hEntType.OriginClass) then
        hEntType := hEntType.Parent
      else
      begin
        hClass := hEntType.OriginClass;
        break;
      end;
  end
  else
    hClass := FromObj.ClassType;

  Assert(Assigned(hClass));

  Members := GetClassStateMembers(hClass, True, False);
// <<<

as you see, your code is commented (the already commented assertions is double-commented :wink:)

or better, CopyFieldValues should be extracted and get the Class by Parm.
So you could also check with an Assertion, that this fits and we could enter the parent-class from outside

Sorry, I didn't understand your last paragraph. The code was commented for a reason, note that CopyFieldValues is mostly an "internal" explorer method and not designed or created to be used directly.