Telerik blogs

Introduction

This blog post demonstrates how to set up a Telerik OpenAccess ORM project for use with Oracle databases. We will use the Visual Designer to design our domain classes and then generate the corresponding Oracle database schema.

Install ODP.NET

Telerik OpenAccess ORM uses the ADO.NET (Oracle.DataAcces.Client) Provider from Oracle called ODP.NET. This can be downloaded from the Oracle Website.

The way to your model

Create a new solution in Visual Studio and add a new project of the type ‘Class Library’.

 

After creating the ‘Class Library’ our next step is to create a domain model. To do this we use the ‘Domain Model Wizard’. To invoke the wizard, right-click your project and select (Telerik OpenAccess ORM -> Add Domain Model) as shown below.

1-AddDomainModel

 

Now you get asked for some details about your domain model. In our case we want to start from scratch so we choose ‘Empty domain model’ and select Oracle as our backend. You can tweak various settings related to code generation, pluralization etc. in the following pages. For our example we will accept the defaults, so click ‘Finish’.

 

2-EmptyDomainModel

 

After you clicked ‘Finish’, Telerik OpenAccess ORM will add references to ‘Telerik.OpenAccess’ and ‘Telerik.OpenAccess.35.Extensions’ to your project. You will get asked to reload your project which you can do by clicking the ‘Ok’ button. The reason to do this is that Telerik OpenAccess ORM adds an MSBuild Task to your project file which will be used to enhance the compiled .NET assemblies. You can find details about this here. At this point you can see the generated domain model as an .rlinq file in your project.

 

3-Solution

 

A double-click on that file will open the Visual Designer where we can start modeling our domain classes. The Toolbox will look like this.

 

4-DomainClass

 

To generate the model, drag a ‘Domain Class’ item into your workspace and start designing it as you prefer. For this example we have created two ‘Domain Class’ objects. Each object has a primary key. The ‘Company’ has a list of ‘Employees’ and the ‘Employee’ a reference to the ‘Company’. The default name of the table’s and their columns are derived from the Name property of the ‘Domain Class’ objects and from individual properties of the classes and the naming rules that are specified in the ‘Model settings’.

This would be enough for our example.

 

5-DomainClasses

 

Below is an example of the ‘Define naming rules’ dialog.

 

6-ModelSettings

 

Generate the database for our model

Now that you have designed our domain model it’s time to generate the database for it. You can do this by right-clicking on an empty space in the Visual Designer and click on ‘Update Database from Model’

 

7-UpdateModelFromDatabase

 

The first step is to give some details to Telerik OpenAccess ORM where you want to save your objects. In our case we want to use an Oracle database. If you don’t have a connection configured yet, you can do this by pressing the ‘New Connection’ button. There you have the ability to select your Provider (in our case the ODP.NET Provider). Afterwards you can specify your tnsnames database name with the appropriate credentials. (You need to have ODP.net installed in order to select the ODP.net provider. See the point ‘Install ODP.NET’). If you don’t see the ODP.NET provider, you can choose ‘.NET Framework Data Provider for Oracle’. Telerik OpenAccess ORM will automatically use the ODP.NET provider, because we have chosen an Oracle as the backend. You can specify the proper provider in you app.config file.

 

   1: providerName="Oracle.DataAccess.Client" 

 

8-1-ConnectionProperties

 

Press the ‘Test Connection’ button to check if your connection is configured successfully.
As a result of your settings you will see a connection string in the ‘Database Connection’ dialog.

 

9-SchemaUpdateWizard

 

In the next step you will be asked whether to generate the schema creation script or a migration script in case you already have an existing database with schema objects in it. We will choose ‘Generate and Execute Migration Update Script’.

 

10-ExecuteSchemaMigrationScript

 

This will lead to the next step where we get a generated ‘DDL’ for our domain model. Pressing the ‘Execute Script’ button will execute this script against our database.

 

11-ExecuteModel

 

The result is a new table schema on our database.

 

12-Schema

 

Start Programming with your model

Code Example

After we have generated the domain model and brought this to our database, it’s time to go on and work with our model. Therefore we create a new ‘ConsoleApplication’ Project and add a reference to our ClassLibrary holding the domain model. Additionally you have to add references to ‘Telerik.OpenAccess’ and ‘Telerik.OpenAccess.35.Extensions’.

The following code will generate a new object of our designed domain model class ( MyNewDomainClass) and makes this instance persistent using the context of our model designed with the Visual Designer.

   1: static void Main(string[] args)
   2: { 
   3: using (var ctx = new EntitiesModel())
   4:     { 
   5:         var company = new Company() { CompanyName = "Telerik" };
   6:         var employee = new Employee() { EmployeeName = "Emp1", Company = company };
   7:         ctx.Add(employee);
   8:         ctx.SaveChanges();
   9:  
  10:         var persistentCompany = (from x in ctx.Companies
  11: where x.CompanyId == company.CompanyId
  12:                                     select x).FirstOrDefault();
  13:  
  14:         Console.WriteLine(company.CompanyName.Equals(persistentCompany.CompanyName) == true ? "Equal" : "Not Equal");
  15:         Console.ReadKey();                
  16:     }
  17: }
That’s all you have to do to get a simple Telerik OpenAccess ORM based oracle application running.

Comments

Comments are disabled in preview mode.