Skip to content

Entity Framework TableNameAttribute [Mapping]

Victor Tomaili edited this page May 3, 2021 · 1 revision

(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](ColumnAttribute [Mapping])

Clone this wiki locally