-
Notifications
You must be signed in to change notification settings - Fork 226
Data Annotations
Simon Hughes edited this page Nov 19, 2019
·
3 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.