Show/Hide Toolbars

TMS Data Modeler Documentation

Navigation: TMS Aurelius Export > Customization Script

Adding DBIndex Attributes From Table Indexes

Scroll Prev Top Next More

TMS Data Modeler doesn't generate DBIndex attributes from existing table indexes. But if you need it, you can do it using the following code snippet:

 

procedure OnClassGenerated(Args: TClassGeneratedArgs);
var                                                    
  I, J: Integer;
  Idx: TGDAOIndex;    
  Fields: string;         
  Attr: TCodeAttributeDeclaration;
begin                                             
  for I := 0 to Args.DBTable.Indexes.Count - 1 do
  begin                                               
    Idx := Args.DBTable.Indexes[I];
    Fields := '';
    for J := 0 to Idx.IFields.Count - 1 do          
    begin
      if Fields <> '' then Fields := Fields + ',';
      Fields := Fields + Idx.IFields[J].FieldName;
    end;
    Attr := Args.CodeType.AddAttribute('DBIndex');
    Attr.AddRawArgument('''' + Idx.IndexName + '''');
    Attr.AddRawArgument('''' + Fields + '''');
  end;
end;

 

For example, originally the class would be generated like this:

 

  [Entity]                            
  [Table('Categories')]    
  [Id('FCategoryID', TIdGenerator.IdentityOrSequence)]
  TCategories = class

 

With the following script a DBIndex attribute will be added for each table index:

 

  [Entity]                            
  [Table('Categories')]    
  [Id('FCategoryID', TIdGenerator.IdentityOrSequence)]
  [DBIndex('CategoryName''CategoryName')]
  TCategories = class