The following code library applies only to versions prior to Q2 2013. As of Q2 2013 Telerik OpenAccess ORM supports generation of DataAnnotation attributes out of the box.
||Q1 2012 SP1 (2012.1.301.2)
|Visual Studio version
This project demonstrates how to generate data annotation for your domain types based on the domain model schema.
Data annotations are generated using custom text template that should be included in the domain model project.
This domain model is based on SofiaCarRental21 sample database.
SofiaCarRental21 database can be created using the SofiaCarRental21.sql script.
Data annotation attributes that are supported by this custom code generation template are:
In order to achieve the desired result please:
Create a domain model
Add the DataAnnotations.tt template to the project. Set its Custom Tool to "TextTemplatingFileGenerator" if not set.
Edit the template file:
Please change line 11:
For Visual Studio 2010 it should be:
<#@ Assembly Name="C:\Program Files (x86)\Telerik\OpenAccess ORM\dsl2010\Telerik.OpenAccess.Common.UI.dll" #>
and for Visual Studio 2012:
<#@ Assembly Name="C:\Program Files (x86)\Telerik\OpenAccess ORM\dsl2012\Telerik.OpenAccess.Common.UI.dll" #>
You should replace the value of the assembly name with the full path to Telerik.OpenAccess.Common.UI assembly on YOUR machine.
Please change line 13:
<#@ Assembly Name="C:\Program Files (x86)\Telerik\OpenAccess ORM\bin\Telerik.OpenAccess.dll" #>
You should replace the value of the assembly name with the full path to Telerik.OpenAccess assembly on YOUR machine.
OPTIONAL: Edit the name of the .rlinq file on line 62:
//return @"[YOUR RLINQ FILE PATH]";
By default the template will search the directory where it resides for .rlinq files. If it finds one it will use it.
You have to change the rlinq file path if:
there are more than one domain models in your project
the rlinq file discovery routine fails to find your rlinq file for some reason
Transform the DataAnnotations.tt template either by saving it or by invoking the Transform All Templates command in Visual Studio.
Enjoy your auto-generated data annotations.
If you make any changes in the domain model that affect the data annotation (like addition of new column or change of the allowed string length) you should consider regenerating the data annotation code by invoking Transform All Templates.
Keep in mind that changes made in the generated code file could easily get lost if the file is regenerated!
If you need one-time code generation please delete/exclude from project the DataAnnotations.tt in order to prevent any code loss in the generated file.
If you want to add additional data annotation attributes you can do it in the generated file, but make sure that the text template won't overwrite your changes.