Back in Q2 2010 Telerik OpenAccess ORM introduced an Upgrade Tool which converted projects created with the old Reverse Mapping Wizard to use the Visual Designer. Well, Q1 2011 introduces a much improved second version of this useful tool.
What are the improvements? Unlike the previous version that supported reverse-mapped projects only, the new Upgrade Tool can convert projects built upon Reverse and forward-mapped projects. And the best part of it is that, besides the Visual Designer, is that it utilizes the updated full-featured Q1 2011 Fluent Mapping API to achieve this.
To upgrade your existing project and continue your development with the new API, open your existing reverse-mapped project in Visual Studio, and start the Upgrade Tool from the Telerik OpenAccess ORM menu:
The first screen of the converter asks you to select the type of mapping you have used for your existing project and gives a few guidelines:
Clicking next opens the second and last page of the tool which describes what will happen during the conversion:
Just clicking on “Convert” does all the magic! What is more, the Upgrade Tool creates a back-up of your project, so you can always restore it to the state it was prior to converting it in case you do not feel confident with the upgrading process.
The Forward Mapping or Code-First approach has always been about the users writing their own code, not depending on automatic code-generation by the ORM. That is why the most important goal for us when we thought about upgrading Forward Mapping projects, was to leave the code that the user has written intact and unchanged. That is also the reason why the Visual Designer is not really applicable for old Forward Mapping projects as the current Visual Designer always generates the entities on its own. While it is safe for us to replace the entities generated by the Reverse Mapping Wizard with classes generated by the designer, this is not an option for Forward mapping.
So, for you guys that prefer writing code instead of using drag & drop, we generate your mapping using the Fluent API – which is evolving into our ultimate code-first solution with every new release!
Converting your project results in two new files added to it. One of them is FluentMetadataSource, where all of the Fluent Mapping code is generated as well as a class deriving from the OpenAccessContext class containing IQueryable end-points for all of your entities. In opposite to the files generated by the designer, these files are never re-generated which means you can continue writing your own code there, thus it is possible to extend your model with Fluent Mapping code by yourself.
Here is an example of Fluent Mapping Code produced by the upgrade tool:
DatabaseConnection1FluentMetadataSource : FluentMetadataSource
List<MappingConfiguration> mappingConfigurations =
MappingConfiguration<Category> categoryConfiguration =
MappingConfiguration<Category> configuration =
configuration.HasProperty(x => x.CategoryID).IsIdentity().HasFieldName(
configuration.HasAssociation(x => x.Products).MapJoinTable();
We configure the mapping for a sample “Category” entity and it is easy to see which are the methods you could plug into so you can extend your mapping for the entity.
Things are very simple in this scenario. The tool generates a n OpenAccess model (*.rlinq) file where your mapping is defined. If there is an ObjectScopeProvider class in the project, its implementation will be changed so that it uses the OpenAccessContext API.
One thing we should mention is that the Fluent Mapping code generation is also applicable for reverse-mapped projects; the difference is that the classes generated by the Reverse Mapping Wizard will not be deleted, but will be used to configure the Fluent Metadata Source. In case you would like to generate an .rlinq file, the Reverse Mapping classes will be deleted and any custom logic inside them will be gone too.
Try it out and share your feedback! Download Telerik OpenAccess ORM Q1 2011 today!