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

Database First Scenario

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 applications and services are based on the domain model. This model represents application data as a set of persistent classes and relationships that are mapped to a defined data source. A domain model consists of a conceptual model expressed as types and relationships, a storage model that represents the schema of the logical model, and a mapping between the two. The development phase of a project usually starts with the conceptual model, and then the storage model is derived from the conceptual model.

To meet the needs of developers who want to derive a domain model from an existing database, Telerik Data Access provides a set of modeling tools that generate a domain model, validate a domain model, and create persistent classes based on the storage (database) model. The database first scenario has been available since the very beginning of Telerik Data Access.

Creating the Project

To create a new Telerik Data Access Domain Model using database first mapping:

  1. Select File > New Project in Visual Studio.
  2. In the list of Installed Templates on the left side of the dialog, select Visual C# or Visual Basic.
  3. Then select Telerik Data Access Class Library. Give the new project a name, and then click OK.

  4. This will start the Telerik Data Access New Domain Model Wizard. The first step in the wizard lets you choose the type of model you want to use. In this step, you have the option of generating a model from a database or starting with an empty model. This topic deals with generating a model from an existing database, so select the Populate from Database option as shown on the figure below.

  5. Select the backend provider (the default backend is MSSQL). Give the model a name or use the default one, and click Next to proceed. For more information about the supported database, check out here.

  6. The next page in the wizard lets you specify the data connection for your domain model. If you have previously created connections they will show up in the list. The next image shows this step in the wizard.

    If you haven't created any connections you will need to create one, and this can be done by clicking the New Connection button. This will open the standard Connection Properties dialog. The Connection Properties dialog looks very similar to most of the other SQL Server connection dialogs in which you need to provide the server name, authentication method, and the database name. Select the target database and click the Test Connection button to make sure all the connection settings are correct. If everything checks out fine, click OK.

    Clicking OK will take you back to the data connection page of the wizard with your new connection shown in the connection drop-down. The other option in Setup Database Connection page allows you to modify the name of the connection string. This should be a unique name, which identifies the connection string in the <connectionStrings> </connectionStrings> section of the App.Config or Web.Config file (depending on the project type). For the sake of this demo, accept the default name. Click Next, once you have made all the necessary selections.

  7. The next step of the wizard allows you to select the database objects to include in the domain model. On this page, you can select tables, views, and stored procedures.

  8. At this point your model is ready to be built. But before you click the Finish button, explore the rest of the pages in the wizard. Click Next, once you have made all necessary selections.

  9. The next step of the wizard allows you to specify how class and member names are generated. For more information, read here.

    The Naming Rules dialog consists of three parts - naming rules for classes, fields and properties. For the sake of this demo, accept the default settings and click Next.

  10. The last step of the Telerik Data Access Create Domain Model Wizard is the Advanced Options dialog. Here you could specify model and code generation settings.

    Code generation lets you use templates to generate part of your application's source code and other resources from a model. Telerik Data Access uses code generation templates to generate your persistent classes. One common scenario is to modify the code generation templates used by Telerik Data Access Visual Designer, in order to implement automatically INotifyPropertyChanging/ed interfaces in the generated persistent classes. For more information about that and other scenarios, please refer to the Customizing Code Generation section.

  11. Go ahead and click the Finish button on the Telerik Data Access Create Domain Model Wizard.

What Just Happened?

When you click finish, the wizard will enhance the project to work with Telerik Data Access. In addition, it will add the required references, it will create a new configuration file containing the connection string to the target database, and will add an .rlinq file to the project.

To see the generated domain classes in VB projects, use the Show All Files command from the Solution Explorer toolbar.

Exploring the Model

Double click the EntitiesModel.rlinq file to open the generated domain model in the Visual Designer.

Next Steps

In this topic, you learnt how to perform the following tasks with Telerik Data Access:

  • Create a new Telerik Data Access Class Library project. Telerik Data Access provides various project templates, allowing you to create new projects based on Telerik Data Access in just few clicks. Read more
  • Work with the Telerik Data Access Create New Model Wizard. The wizard allows you to generate a new domain model. Read more
  • At this point the model is ready to be connected up to the UI, or run the Data Services Wizard to create a service layer over the model. Read more