TableNameAttribute [Mapping]

Estrusco edited this page Apr 22, 2016 · 2 revisions
Clone this wiki locally

(from the official guide)

[namespace: Serenity.Data.Mapping] - [assembly: Serenity.Data]

By default, a row class is considered to match a table in database with the same name, but Row suffix removed.

If table name in database is different from row class name, use this attribute:

[TableName("TheCustomers")]
public class CustomerRow : Row
{
   public string StreetAddress
   {
      get { return Fields.StreetAddress[this]; }
      set { Fields.StreetAddress[this] = value; }
   }
}
SELECT
T0.StreetAddress AS [StreetAddress]
FROM TheCustomers T0

You may also use brackets or quotes:

[TableName("[My Customers]")]
public class CustomerRow : Row
{
   public string StreetAddress
   {
      get { return Fields.StreetAddress[this]; }
      set { Fields.StreetAddress[this] = value; }
   }
}
SELECT
T0.StreetAddress AS [StreetAddress]
FROM [My Customers] T0

Again, prefer brackets for database compability

See also: ColumnAttribute