The Q2 2014 release of Telerik Data Access brings you a new highly requested feature – Attributes Support for Domain Models. You will no longer need to customize code generation templates or write buddy classes to decorate the persistent classes of your Domain Models with attributes. Instead Telerik Data Access will provide you with the new Manage Attributes Model Operation and Attribute Editor dialog to add and remove attributes for your persistent classes and their members. In addition to attributes from the framework or third party libraries, custom attributes are also supported by both the Model Operation and the new dialog.
Let us check out this new functionality in action. To do this we will go through a common scenario where we need to use our persistent classes as a data contract for a Plain WCF Service. We will decorate the entities in the following model with the required attributes – DataContract, DataMember and KnownType:
The Manage Attributes Model Operation lets you quickly and easily add and remove attributes for multiple entities or members at once. We will use this model operation to add DataContract attribute to our entities and DataMember to their members.
To add the DataContract attribute three easy steps are required:
Pressing the Execute button will apply the attribute to the model`s metadata.
The process for adding the DataMember attribute to the members of the entities is similarly easy. All you need to do is:
After closing the Model Operations dialog you would need to Save the model in order for the attributes to be applied in the code.
We have added the DataContract and DataMember attributes. But, there is inheritance defined between our classes, so we need to add two KnownType attributes to the base class Person – one for Student and one for Teacher. This is where the Attributes Editor comes into action as it is perfect for managing the attributes of a single persistent class or member.
You can run the Attributes Editor from the properties window of e persistent class or property in the Visual Designer.
Now, all you need to do is type the KnownType attribute in the textbox and press the Add button. As with the Manage Attributes Model Operation, here the Attribute text box also offers Auto-Complete functionality in order to ease the input of the desired attribute. After pressing the OK button, you will need to Save the model before the attributes are applied to the code.
Your classes are now decorated with the attributes required to use them as the data contract for your Plain WCF Service.
The Manage Attributes Model Operation and Attributes Editor can greatly ease the management of your model in scenarios where you need to add or remove attributes. Q2 2014 is already live, you can download it here and try out our new Visual Designer Attributes Support yourself.
Subscribe to be the first to get our expert-written articles and tutorials for developers!
All fields are required