Entities generation revamped in Xomega 7.8

Starting from release 7.8, Xomega has completely upgraded the way Entity Framework classes are generated.

Entity Framework classes are generated now directly from the Xomega model.

Previously, the Entity Framework (EF) classes were generated using standard Model-First EF T4 templates from an Entity Data Model (EDM), which was in turn generated from the Xomega model. Now they are generated directly from the Xomega model using a new Xomega generator called EF Domain Objects. Generating EDM is no longer needed for the application, but that generator is still available in case you want to view your entity model on graphical diagrams.

This provides a lot of benefits as a result, such as the following.

  • Full control over the way Entity Framework classes are generated.
  • Ability to output generated classes using Xomega standards - grouped in sub-folders by module, individual files in a single folder, or even all generated classes in a single file.
  • Generated classes and their fields now have documentation comments from their Xomega model’s doc elements to help developers use them correctly.
  • No need to run T4 templates after the Xomega generation, which was failing sporadically, resulting in compile and run-time errors after domain model updates.
  • No need to maintain edm:type configurations on logical types, unless you need to generate an EDM for diagrams, since Xomega uses now the clr:type configurations instead.
  • Ability to use Entity Framework Core in the future, which does not support EDM.

Entity configurations are generated by each entity using Fluent API.

Without the generated EDM, the EF classes use Fluent API now to configure the domain entities. Unlike the standard EF generators that create entities from database tables and output all configurations into a single method OnModelCreating of the generated DbContext class, configurations for entities generated from the Xomega domain objects are segregated neatly into separate files for each entity, which makes them much more easier to work with, and keeps the code for the entities and the context very clean.

Fluent API allows you to easily customize or override configurations of each entity without touching the generated code. For example, you can tweak configurations of any property,   entity or relationship in a subclass of the generated DB context, and then register that subclass with the Dependency Injection container.

No comments:

Post a Comment