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

Walkthrough: Creating Domain Model

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.

In the previous topic was demonstrated how to migrate the SofiaCarRental database from SQL Server to SQL Azure. In this task you will learn how to create a new Telerik Data Access Domain Model and connect it to the SofiaCarRental database on SQL Azure.

  1. Open Microsoft Visual Studio 2010 in elevated administrator mode.
  2. From the File menu, choose New and then Project.
  3. In the New Project dialog, expand the language of your preference. Select Windows and then select Windows Forms Application. Type GettingStartedOASqlAzure for a name of your project.
  4. Click OK to create the project. Next you will add a new Telerik Data Access Domain Model and configure it to read data from SQL Azure.
  5. Right-click the GettingStartedOASqlAzure, point Add and then New Item.
  6. In the Add New Item dialog box, choose Data and then Telerik Data Access Domain Model. Click Add.
  7. The Select Domain Model Type Dialog appears.

    1. Select the Populate from database domain model type.
    2. From the Backend drop-down, choose Microsoft SQL Azure.
    3. Specify SofiaCarRentalDbContext for name of the model.

  8. Click Next to continue. The Setup Database Connection Dialog appears. The most tricky moment when connecting Telerik Data Access Domain Model with SQL Azure is in the Data Connection Dialog. You need to set up the connection string manually.

  9. In the Connection String field enter the following connection string.

    Server=tcp:*server_name*;Database=*SofiaCarRental*;User ID=*user_name*@*server_name*;Password=*myPassword*;Trusted_Connection=False;Encrypt=True;

    You should specify the following parameters in the connection string:

    • server_name - the name of your assigned server.
    • user_name - this is a valid logon user granted to use the SofiaCarRental. By default you could use the database master.
    • myPassword - your password.

  10. Click Next to proceed. The rest of the actions in this topic are pretty familiar for all Telerik Data Access developers.

  11. In the Choose Database Items Dialog select only the Cars table and click Finish to generate the model.

To test that the generated OpenAccessContext works correctly and loads data from SQL Azure, you need to create a simple user interface for the main form and display some data.

  1. Open the Form1.cs class. Drag a new DataGridView control to the form.
  2. Switch to the code-behind and declare a new instance of the SofiaCarRentalDbContext.

    private SofiaCarRentalDbContext dbContext = new SofiaCarRentalDbContext();
    Private dbContext As New SofiaCarRentalDbContext()
  3. Add the following code in the constructor of the form. All records from the Cars table is loaded and displayed in the DataGridView.

    public Form1()
       dataGridView1.DataSource = dbContext.Cars.ToList();
    Public Sub New()
     dataGridView1.DataSource = dbContext.Cars.ToList()
    End Sub
  4. Run your application to ensure that the data is loaded.

See Also