This video series will get you started in creating your Domain Model based on an already existing database. It will demonstrate how to connect to the database, select the necessary objects and define the Domain Model naming settings and advanced options. This mapping approach is known as Database-first, Schema-first, or Reverse Mapping
In this video you will learn how to get started building a web application based on an existing database using OpenAccess ORM reverse mapping. In addition you will learn how to extend the data model to include custom properties, and bind the data model to a RadGrid using the OpenAccessLinqDataSource.
In this video series you will learn how to create MVC 3 applications using OpenAccess ORM Database First Approach.
Telerik OpenAccess ORM 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 OpenAccess ORM 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 OpenAccess ORM.
Creating the Project
To create a new Telerik OpenAccess Domain Model using database first mapping:
- Select File > New Project in Visual Studio.
- In the list of Installed Templates on the left side of the dialog, select Visual C# or Visual Basic.
- Then select Telerik OpenAccess Class Library. Give the new project a name, and then click OK.
- This will start the OpenAccess 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- The last step of the OpenAccess 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 OpenAccess ORM uses code generation templates to generate your persistent classes. One common scenario is to modify the code generation templates used by OpenAccess 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.
- Go ahead and click the Finish button on the OpenAccess Create Domain Model Wizard.
What Just Happened?
When you click finish, the wizard will enhance the project to work with OpenAccess. 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.NET 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.
In this topic, you learnt how to perform the following tasks with Telerik OpenAccess ORM:
- Create a new OpenAccess Class Library project. Telerik OpenAccess ORM provides various project templates, allowing you to create new projects based on OpenAccess ORM in just few clicks. Read more
- Work with the OpenAccess 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