A general recommendation is to isolate the Data Access models used in your applications in separate class library projects. The benefit is that the models can participate in different scenarios with just a simple configuration of the consuming project. The setup utilizes the Telerik.DataAccess.Core NuGet package, and the current tutorial will guide you across the config process. For illustrative purposes, it uses the fluent model produced by the steps in the Code Only Scenario article.
The application you are going to configure in this tutorial is a console application, but the same steps could be applied for all other types of projects, such as WinFroms, WPF, ASP.NET, etc.
- Right-click on the name of the solution in Solution Explorer, and select the Add > New Project... command.
In the Add New Project dialogue, select the Console Application template, name the project FluentModelClient, and click OK.
Right-click on the FluentModelClient project and select the Manage NuGet Packages... command. In the dialogue, search for Telerik.DataAccess.Core and when the package is found, click Install..
The package will add references to the Data Access assemblies required for the proper runtime behaviour of the application: Telerik.OpenAccess, Telerik.OpenAccess.35.Extensions, Telerik.OpenAccess.40.Extensions, and Telerik.OpenAccess.Runtime.
In the FluentModelClient project, add a reference to the SampleFluentModel project.
The last step is to ensure that the client project "has" access to the database. What you normally do when you have an existing config file in the client project is to copy the connection string from the App.config in the library project and paste it in the <connectionStrings/> section in the client config file
If you don't have an existing config file in the client project, you can simply copy and paste the entire config file.
In a nutshell, the reason behind this step is that the FluentModelClient project is your executable project. When you run the application, all settings (configurations) are taken from that project. Respectively, the OpenAccessContext will try to retrieve the connection string from the config file in the executable project. If such doesn't exist, the initialization of the OpenAccessContext will fail.
At this point you are ready to consume the model.
So, these are the three important pieces you need in order to configure your applications.
- Reference to the library project.
- Integration with the the Telerik.DataAccess.Core NuGet package.
- The connection string to the database.
An additional step you need to consider is making the client (consuming) project a start up project. Right-click the client (consuming) project in Solution Explorer and select Set as Startup Project.
Once your client (consuming) project is configured to use the fluent model, the next step is to start performing CRUD operations.