Article relates to
Telerik OpenAccess ORM
September 13, 2012
Last modified by
The Fluent Mapping Code Generation functionality allows you to mix the Code Only and Database First approaches. It allows you to generate most of the necessary code automatically as it is done with the Visual Designer domain models. At the same time, since the generated code contains Fluent Mapping API, you can benefit from the capabilities this API offers you for modifying and extending the domain model.
The fluent code model generation is the third mapping type available in Telerik OpenAccess ORM.
The "Fluent" type of code generation is intended to be used as a onetime code generation only. Unlike the "Xml" and "Attribute" types, where it is assumed you will be working with Visual Designer, making updates and applying them to the model or the database through our wizards, the "Fluent" is supposed to just help you with the initial efforts in defining your Code Only data access layer.
In general, the Fluent Mapping API is provided as an alternative of Visual Designer, so you would generally choose it if you prefer defining the mapping in a declarative manner through code. However, sometimes mapping a very large database can require a very long coding effort. The Fluent Code generation will do the hard and boring part of the mapping code and leave only the customization to you.
When you have fluent code generation and then try to use Visual Designer (e.g. to perform updates from the database), you might get strange results as the fluent mapping is different and much more complex than the other two types of generated code. SOLUTION
When you use Fluent Code Generation, what we would recommend is to extract the auto-generated fluent code files and delete the .rlinq file so that no code is generated automatically afterwards.
Let’s take a look at the following domain model where fluent code generation is used:
Considering the previous recommendation we need to the extract the following files (see the selected files below) and after that delete the .rlinq file.
The generated persistent classes and fluent metadata source can be extracted automatically by using a code generation option in Visual Designer. However, the generated OpenAccessContext (the EntitiesModel.cs file) should be extracted manually. Extracting the Generated Domain Classes and FluentMetadataSource
To extract the generated domain classes and FluentMetadataSource:
1.Double-click the Rlinq file to open Visual Designer.
2.Open Model Settings Dialog and navigate to the Code Generation tab page.
3.Use the Project Folder option to specify a destination folder in the solution where all classes will be generated in.
4.Click OK to close the dialog.
5.Save your .rlinq file to regenerate (extract a copy) the domain classes.
The second step is to extract the OpenAccessContext, i.e. the EntitiesModel.cs file. Extracting the OpenAccessContext
To extract the OpenAccessContext:
1.Open Windows Explorer and navigate to the folder containing your OpenAccessModel project.
2.Copy the file containing the OpenAccessContext (e.g. EntitiesModel.cs).
3.Paste it in the folder with the extracted domain classes (e.g. in the FluentModel folder).
4.Go back in Visual Studio and include the extracted OpenAccessContext in the project structure.
The only step left is to delete the .rlinq file.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.