Using property as "Id" attribute name

Hello,

I'm trying to specify a propery name as Id for my entities:

  [Entity]
  [Table('t_users')]
  [Model(STR_MODEL_SYSTEM)]
  [Id('recno', TIdGenerator.IdentityOrSequence)]
  TBTUser = class(TBTEntityBase)//, IEntityBase<TBTUser>)
  private
    [Column('recno', [TColumnProp.Required])]
    Frecno: Aurelius.Types.Nullable.Nullable<Int64>;
   {...}
  public
    property recno: Aurelius.Types.Nullable.Nullable<Int64> read frecno write frecno;
   {...}
  end;

The code above fails with this error:

Project WinEUR_entities_test.exe raised exception class EInvalidIdMemberName with message 'Invalid member name "recno" defined in Id attribute on class TBTUser.'.

If, howver, I change the Id attribute line to the following one, it works:

  [Id('Frecno', TIdGenerator.IdentityOrSequence)]

Now, if I refere to this http://www.tmssoftware.biz/business/aurelius/doc/web/id.html I read:

AMemberName: Contains the name of field or property that identifies the object


So, why is it not working in my case ?

I need to reference the property and not the field for another class where I have many different entities that share the same structure and therefore all use the same ancestor class (not an entity: these are different data store in different, unrelated tables).

Hello Stephane,


If you want to refer to the property, then it's the property that should be mapped. Id attribute must refer to a mapped class member:



 [Entity]
  [Table('t_users')]
  [Model(STR_MODEL_SYSTEM)]
  [Id('recno', TIdGenerator.IdentityOrSequence)]
  TBTUser = class(TBTEntityBase)//, IEntityBase<TBTUser>)
  private
    Frecno: Aurelius.Types.Nullable.Nullable<Int64>;
   {...}
  public
    [Column('recno', [TColumnProp.Required])]
    property recno: Aurelius.Types.Nullable.Nullable<Int64> read frecno write frecno;
   {...}
  end;

As a side comment, I believe you should not use Nullable for Ids. They should not accept null values in database.

Thank you for your answer: you're right about decorating the property instead of the field. Sorry about that.


As for the null, it is correct but I need to do it this way because I need to specify the values myself (it's an import from another DB system and I need to keep the existing IDs)