Telerik blogs

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:

Manage Attributes Model Operation

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:

  1. Run the Model Operations dialog.
  2. Select the required Entities.
  3. Select the Manage Attributes Model Operation and enter the DataContract attribute. The attribute text box comes with Auto-Complete functionality which makes entering the correct attribute easy.


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:

  1. Switch the Display Mode to Members.
  2. Select all the required members.
  3. Select the Manage Attributes Model Operation and enter the DataMember attribute. Complete the operation by pressing Execute.

After closing the Model Operations dialog you would need to Save the model in order for the attributes to be applied in the code.

Attributes Editor

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. 

Join us on 24th of June for our free online conference - Be Responsive: .NET UI for Any Device and be the first to see what powerful new features lie in store for you in the Q2 2014 DevCraft release.

570x100-telerik-blogs

About the Author

Kristian Nikolov

Kristian Nikolov is Support Officer.

Comments

Comments are disabled in preview mode.