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.
Telerik OpenAccess ORM uses the ADO.NET (Oracle.DataAcces.Client) Provider from Oracle called ODP.NET. This can be downloaded from the Oracle Website.
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.
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’.
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.
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.
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.
Below is an example of the ‘Define naming rules’ dialog.
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’
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.
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.
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’.
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.
The result is a new table schema on our database.
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.
Subscribe to be the first to get our expert-written articles and tutorials for developers!