-
Notifications
You must be signed in to change notification settings - Fork 226
Data Annotations
Simon Hughes edited this page Nov 19, 2019
·
5 revisions
You can add data annotations using the column.Attributes list within UpdateColumn function. This can include custom attributes too.
Example:
Settings.UpdateColumn = delegate(Column column, Table table, List<EnumDefinition> enumDefinitions)
{
column.Attributes.Add($"[Display(Name = \"{column.DisplayName}\")]");
if (column.IsPrimaryKey)
column.Attributes.Add("[Key]");
if (column.IsPrimaryKey && table.NameHumanCase.Equals("SomeTable", StringComparison.InvariantCultureIgnoreCase))
column.Attributes.Add("[SomeCustomAttribute]");
}Adding in attributes will require extra namespaces. These can be added to your Settings.AdditionalNamespaces array in your <database>.tt file.
- Home
- Compared with the Microsoft scaffolder
- Connection strings
- JetBrains Rider
- Upgrading from v3 to v4
- Saving .tt does nothing
- Settings A-Z - every setting, with a page each
- Common Settings Types Explained
- Settings Callbacks
- Settings runtime values and helpers
- Filtering
- Full Control Over the Generated Code
- Enum Generation from Table Data
- Owned Entities
- JSON column support
- Global Query Filters
- Extended Property Names Feature
- Partial Properties
- File-Scoped Namespaces
- Data Annotations
- Spatial Types
- HierarchyId
- RowVersion and TimeStamp columns
- Lazy Loading
- Stored proc result sets