When you use the Fluent Mapping API, you need to create a custom fluent context class that derives from the OpenAccessContext class. It will represent the shape of your model and will act as a gateway to your database. Next you could start writing queries against your context, load data, insert, update and delete objects from the database. However, there is a significant issue regarding the Telerik Data Access Enhancer. Telerik Data Access uses Enhancer, which is a special enhancer program, to read and process compiled .NET assemblies for adding persistence capability. The Enhancer can be called from the command line, but normally the enhancer is called directly by Visual Studio during build time to process the .NET assemblies in your project. The Enhancer injects the lazy loading and change tracking code into your persistent classes and replaces the read and write calls to persistent fields. Enhancement must be executed on all assemblies containing persistent classes or code that touches public fields of persistent objects. If you have used one of the Telerik Data Access wizards to configure your project, the enhancement is already configured and everything runs out of the box. Nevertheless, it is sometimes necessary to understand how the enhancer is called. Especially to integrate the enhancer into an automatic build process. The enhancer has to collect all the mapping information for the assembly that you want to enhance and the referenced assemblies which contain persistent classes as well. Telerik Data Access has two mechanisms to define the mapping - either XML only or CLR Attributes only. If you have added Telerik Data Access Domain Model via the "Add New Item" to your project, the enhancement is already added to the MsBuild project file and no changes are necessary. However, fluent mapping means that there isn't an .RLINQ file. That's why you have to enhance your project manually. Or in other words, you have to integrate the Telerik Data Access Enhancer in your Fluent Mapping project.
When you use the Telerik Data Access Fluent Library template, the Telerik Data Access Enhancer is automatically integrated in your project.
To integrate the Telerik Data Access Enhanced:
- Right-click on your project in the Solution Explorer and select Unload Project.
- Again in the Solution Explorer, right-click on the unloaded project and select Edit ProjectName.csproj.
In your csproj file, find a line like this one:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
And import the following code after the aforementioned line:
<Import Condition="Exists('$(MSBuildExtensionsPath)\OpenAccess.targets')" Project="$(MSBuildExtensionsPath)\OpenAccess.targets" />
Save your changes. Right-click on your project in the Solution Explorer and select Reload Project.
By implementing the above-mentioned steps you guarantee that the Telerik Data Access Enhancer will be integrated with your Fluent Mapping project. Check out the next topic to see how to troubleshoot your fluent mapping applications.