Get DB Tablename

Hello Wagner,

if you are online for a quick question.
I also continue to search the source code myself.

I need the following function.

class function TDBTools.GetDBTablename( M: TMappingExplorer; Clazzname: String): String;
begin
  Result := '// to do';
end;

Can I get the DB table name with this approach?

If I need the Class, I have some code

var
  Clazz: TClass;
begin
  Clazz := M.Hierarchy.FindClassByName( Clazzname);
  if Clazz = nil then
    ...

Ok, I think, I found it:

class function TDBTools.GetDBTablename( M: TMappingExplorer; Clazzname: String): String;
var
  Clazz: TClass;
  Table: TMetaTable;
begin
  Clazz := M.Hierarchy.FindClassByName( 'T'+Clazzname);
  if Clazz = nil then
    Exit( '');

  Table := M.GetTable( Clazz);
  if Table <> nil then
    Exit( Table.Name);

  Result := '';
end;

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Your solution is valid. Another valid approach, which is more future proof, is:

  var EntityType := M.EntityTypeFromClass(Clazz);
  if EntityType <> nil then
    Exit(EntityType.Table.Name);