Property not found on class

Hi Wagner,


I want to use inheritance but with different names for the properties in the descendants that map to a common field but it is giving me problems.  Basically I want to do something like this:


  [Entity]
  [Table('ANIMALS')]
  [Sequence('GEN_ANIMAL_ID')]
  [Inheritance(TInheritanceStrategy.SingleTable)]
  [DiscriminatorColumn('DISCRIMINATOR', TDiscriminatorType.dtString)]
  [Id('FID', TIdGenerator.IdentityOrSequence)]
  TVehicleBase = class
  private
    [Column('ID', [TColumnProp.Required])]
    FID: integer;
    [Column('REG', [], 32)]
    FReg: Nullable<string>;
  public
    property Id: integer read FID write FID;
  end;
  
  [Entity]
  [DiscriminatorValue('CAT')]
  TTrailer = class(TVehicleBase)
  private
    //
  public
    property CatLicense: Nullable<string> read FReg write FReg;
  end;

  [Entity]
  [DiscriminatorValue('DOG')]
  TTrailer = class(TVehicleBase)
  private
    //
  public
    property DogLicense: Nullable<string> read FReg write FReg;
  end;
 
If I do this I get the error "property not found on class" when I try to use it in an Aurelius Dataset.  It will work if move the private field and the attribute to the descendants as follows:


  [Entity]
  [Table('ANIMALS')]
  [Sequence('GEN_ANIMAL_ID')]
  [Inheritance(TInheritanceStrategy.SingleTable)]
  [DiscriminatorColumn('DISCRIMINATOR', TDiscriminatorType.dtString)]
  [Id('FID', TIdGenerator.IdentityOrSequence)]
  TVehicleBase = class
  private
    [Column('ID', [TColumnProp.Required])]
    FID: integer;
  public
    property Id: integer read FID write FID;
  end;
  
  [Entity]
  [DiscriminatorValue('CAT')]
  TTrailer = class(TVehicleBase)
  private
    [Column('REG', [], 32)]
    FCatLicense: Nullable<string>;
  public
    property CatLicense: Nullable<string> read FCatLicense write FCatLicense;
  end;

  [Entity]
  [DiscriminatorValue('DOG')]
  TTrailer = class(TVehicleBase)
  private
    [Column('REG', [], 32)]
    FDogLicense: Nullable<string>;
  public
    property DogLicense: Nullable<string> read FDogLicense write FDogLicense;
  end;

But this will mean that if I try to build the database using Aurelius it will try and create a table with two DOG fields!

I've tried various different ways of doing it never seems to work properly.  I guess it's just not possible to have this without issues but I thought I'd just check with you first before I give up and go to plan B.  Any ideas?

Regards

Steve  

with two DOG fields should be with two REG fields

Hi Steve,


it's not clear what you are doing. Aurelius dataset doesn't care much about mapping, if you create a field "DogLicense" it would work even if it's not mapped to the database. That's the property that raised the error?
There should not be a problem with your approach, maybe some more details are needed to check what's going on.

It doesn't work though, try it and see and you'll get the error 'property not found on class' if you bind the classes to an Aurelius Dataset and then try to use them on a grid.  I've got a way to work round it so it's not actually a problem for me but I'm sure it will come up again for someone else.


I have TVehicleBase  that I inherit TVehicle and TTrailer from.  Vehicle.VehicleReg and Trailer.TrailerReg are both stored in the same database field.  I want to be able to build my database from Aurelius so I'm going to change Vehicle.VehicleReg to Vehicle.Reg and Trailer.TrailerReg to Trailer.Reg and I am confident that that will work.      

Hi Steve, sorry but it works here, at least the way I understand it. It's even in our test suite. For example, I have this dog class inheriting from mammal which in turn inherits from animal:


  [Entity]
  [DiscriminatorValue('DOG')]
  TTI_Dog = class(TTI_Mammal)
  strict private
    [Column('DOG_BREED', [], 50)]
    FDogBreed: Nullable<string>;
    FTransientOne: Nullable<integer>;
  public
    property DogBreed: Nullable<string> read FDogBreed write FDogBreed;
    property TransientOne: Nullable<integer> read FTransientOne write FTransientOne;
  end;

Note that TransientOne is not mapped at all. If I create an integer field "TransientOne" in my dataset, it works with no problem.

I'll do a mini project to highlight the issue when I get a chance and email it to you.