-
Notifications
You must be signed in to change notification settings - Fork 806
Entity Framework ColumnAttribute [Mapping]
(from the official guide)
[namespace: Serenity.Data.Mapping] - [assembly: Serenity.Data]
By default a property is considered to match a column in database with the same name.
You can map a property to some other column name in database using Column attribute:
public class CustomerRow : Row
{
[Column("street_address")]
public string StreetAddress
{
get { return Fields.StreetAddress[this]; }
set { Fields.StreetAddress[this] = value; }
}
}
Now the query becomes:
SELECT
T0.street_address AS [StreetAddress]
FROM Customer T0
It is also possible to manually add brackets:
public class CustomerRow : Row
{
[Column("[street_address]")]
public string StreetAddress
{
get { return Fields.StreetAddress[this]; }
set { Fields.StreetAddress[this] = value; }
}
}
SELECT
T0.[street_address] AS [StreetAddress]
FROM Customer T0
If SqlSettings.AutoQuotedIdentifiers is true, brackets are automatically added. Use SqlServer specific brackets ( [] ) if you need to work with multiple database types. These brackets are converted to dialect specific quotes (double quote, backtick etc.) before running queries. But, if you only target one type of database, you may prefer using quotes specific to that database type.
See also: [TableNameAttribute](TableNameAttribute [Mapping])
Copyright © Serenity Platform 2017-present. All rights reserved.
Documentation | Serene Template | Live Demo | Premium Support | Issues | Discussions