Think i have part of my answer. By reading a lot more about TextTemplatesTransformations i have modified my Model1.tt to include:
System.ComponentModel.DataAnnotations;
i have also modified the WriteProperty method to accept an EdmPropertyType. The code now generates multiline annotations for all strings which came from a specified length > 60 or max defined strings. It also generates a maxlength annotation which should hopefully help prevent overflow. If using you will need to modify both the existing WriteProperty overloads as below.
void WriteProperty(CodeGenerationTools code, EdmProperty edmProperty)
{
WriteProperty(Accessibility.ForProperty(edmProperty),
code.Escape(edmProperty.TypeUsage),
code.Escape(edmProperty),
code.SpaceAfter(Accessibility.ForGetter(edmProperty)),
code.SpaceAfter(Accessibility.ForSetter(edmProperty)),edmProperty);
}
void WriteProperty(string accessibility, string type, string name, string getterAccessibility, string setterAccessibility,EdmProperty edmProperty = null)
{
if (type =="string")
{
int maxLength = 0;//66
bool bres = (edmProperty != null
&& Int32.TryParse(edmProperty.TypeUsage.Facets["MaxLength"].Value.ToString(), out maxLength));
if (maxLength > 60) // want to display as a TextArea in html
{
#>
[DataType(DataType.MultilineText)]
[MaxLength(<#=maxLength#>)]
<#+
}
else
if (maxLength < 61 && maxLength > 0)
{
#>
[MaxLength(<#=maxLength#>)]
<#+
}
else
if(maxLength <=0) //varchar(max)
{
#>
[DataType(DataType.MultilineText)]
<#+
}
}
#>
<#=accessibility#> <#=type#> <#=name#> { <#=getterAccessibility#>get; <#=setterAccessibility#>set; }
<#+
}
Ensure that the <#+ lines and the #> lines start at the begining of the line as i think this is a requirement of the TT syntax.
Tim