Data Access has been discontinued. Please refer to this page for more information.

Attributes Mapping

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

Telerik Data Access maps a database to a domain model by either applying attributes or by using an external XML mapping file. When you use the Attributes Mapping Type, the mapping information is exposed as CLR attributes applied to the domain classes and their properties. A domain class is just like any normal object class that you might define as part of your application, except that it is annotated with special information that associates it with a particular database table. These annotations are made as custom attributes on your class declaration. The attributes are only meaningful when you use the class in conjunction with Telerik Data Access. They are similar to the XML serialization attributes in the .NET Framework. These "data" attributes provide Telerik Data Access with enough information to translate queries for your objects into SQL queries against the database and changes to your objects into SQL insert, update and delete commands. In its most elementary form, Telerik Data Access maps a database to a context class, a table to a class, and columns and relationships to properties on those classes. You can also use attributes to map an inheritance hierarchy in your object model. This topic outlines the attributes-based approach.

How to Change the Mapping Type

The mapping type could be specified during the domain model generation, in the Advanced Options Dialog. Once your model is generated, you are still able to change the mapping type. In order to do so, you need to go to the Code Generation Settings tab page in the Model Settings Dialog.

The generated classes and properties will be decorated with attributes that associate them with particular database tables and columns.

Telerik Data Access Attributes

The Telerik.OpenAccess namespace from the Telerik.OpenAccess.dll assembly contains attributes that are used to generate a Telerik Data Access object model that represents the structure and content of a relational database. For more information, check out the CLR Attributes Mapping section.

Generating MetadataContainer from CLR Attributes

Telerik Data Access defines AttributesMetadataSource to help you generating MetadataContainer from CLR Attributes. An important condition when you use the AttributesMetadataSource is the mapping to be done via CLR attributes. The AttributesMetadataSource class, exposes two static factory methods allowing you to create a new AttributesMetadataSource instance from different objects. When you have an instance of the AttributesMetadataSource class, you have to invoke the GetModel method to access the loaded metadata container. For more information, please refer to Using AttributesMetadataSource.