Our code generation templates can be customized so that DataContract
attributes will be added automatically to your persistent classes and their properties respectively.
I have prepared a set of customized templates which will generate the aforementioned attributes, please find them attached to my answer. To apply the templates follow these steps:
- Create a new folder in the project containing your Domain Model. This folder will contain the customized templates.
- Copy the customized templates (DefaultTemplateCS.tt and the entire Includes_ver.2 folder) in the newly created folder.
- Select DefaultTemplateCS.tt in the Solution Explorer, open its properties window and clear the value for the Custom Tool property.
- Double click on the .rlinq file of your model to open the Visual Designer, right-click its surface and select the Show Model Settings... option from the menu. This will open the Model Settings dialog.
- Select the Code Generation tab.
- Chose the Custom Defined option.
- Click the Select Existing... button and select the DefaultTemplateCS.tt from the custom templates folder in your project.
- In your model project add a reference to the System.Runtime.Serialization assembly.
- Save your model and the classes and their properties will be regenerated with their respective properties.
Please note that in order to use instances of the persistent classes as DTOs you will need to detach them from the context before passing them to the client application or attach them to the context after they have been passed to the service by the client application. To do that you can use our Attach/Detach API.
I hope this helps.
OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features
shipped with our latest release!