0

I'm using Linq2DB, LinqToDB.Mapping to map the tables from database.

The class name has a Data Annotation named "Table" to specify the name of the table in de DB. For example:

[Table(@"EXAMPLE_ONLINE")]
public class Example
{
    [Column(@"ID_EXAMPLE")]
    public ulong IdExample { get; set; }
    [Column(@"DESCRIPTION")]
    public string Description { get; set; }
}

How can I get that table name from that Data annotation? Is tehere something like a

Example.GetTableName()

Thank you

qhart
  • 29
  • 6

1 Answers1

0

You can obtain this information from EntityDescriptor:

var tableName = db.MappingSchema.GetEntityDescriptor(typeof(Example)).TableName;

Or you can create extension method:

public static GetTableName<T>(this MappingSchema mappingSchema) 
{
    return db.MappingSchema.GetEntityDescriptor(typeof(T)).TableName;    
}

Also TableName can be optined from ITable<T> interface:

var tableName = db.GetTable<Example>().TableName;    
Svyatoslav Danyliv
  • 21,911
  • 3
  • 16
  • 32