Support for EF Core 6, JSON and YAML Serialization, and More Features in Entity Developer 6.11

April 1st, 2021

Devart is glad to announce the release of Entity Developer 6.11 – a visual ORM designer for a wide variety of ORMs. The new version introduces support for Entity Framework Core 6, greatly improves serialization features in code generation templates adding support for more formats, and offers a number of usability improvements.

Entity Framework Core 6 Support

A new version of Entity Framework Core is currently available as preview versions. You can read about Microsoft plans on the version 6 in their Plan for Entity Framework Core 6.0 article. Another article, What’s New in EF Core 6.0 , describes features, already available in current Preview versions.

The release of Entity Framework Core 6.0 is planned for November 2021, but the following providers for SQL Server, SQLite and PostgreSQL have already supported the current Preview versions:

We have added support for Entity Framework Core 6.0 to Entity Developer, so now you can design EF Core 6 models for this providers with our designer.

Note that you must have .NET 5 or .NET 6 as the target framework for your project if you want to use Entity Framework 6.0.

Serialization Support

We have significantly improved serialization support in the Data Transfer Object template for all supported ORMs, in the EF Core template for EF Core models, and in the DbContext template for Entity Framework v4 – v6 models.

These templates supported Data Contract serialization for a long time. The new Entity Developer version extends its features and adds support for new modern JSON and YAML serializations.

Serialization in Data Transfer Object Template

The Data Transfer Object template now supports the following serializations:

You can use the Serialization Library template property to specify which serialization to use.

Besides, we have added the Serialize Navigation Properties property that allows excluding all or only a part of navigation properties from serialization.

The template also adds an extended property Do Not Serialize for model entity properties, so you now can exclude any property or navigation property from the serialization. Additionally, the template also has the Serialization Name extended property that allows providing a custom property name for serialization.

Serialization in DbContext and EF Core Templates

The DbContext and EF Core templates have all the serialization features of the Data Transfer Objects template – the Serialization Library and Serialize Navigation Properties properties and Do Not Serialize and Serialization Name extended properties. Additionally they have the following additional options for popular use cases.

Serialize Original Column Names

Property names are generated from database columns (as well as vice versa) using naming rules, so a property name can differ from the corresponding database column names. The Serialize Original Column Names template property allows serializing objects identically to the corresponding database objects, which can be necessary in different cases. For example, you may need compatibility with the serialization by the database means, or compatibility with some external serialization system.

Serialize Null Values

If you need to configure serialization in order not to serialize NULL values explicitly, you can use the Serialize Null Values template property. Excluding NULL values from serialization is implemented via adding the following attributes to properties:

  • [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] – for the Newtonsoft.Json library;
  • [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] – for the System.Text.Json library;
  • [YamlMember(DefaultValuesHandling = DefaultValuesHandling.OmitNull)]) – for the YamlDotNet library.

Most serializers allow achieving the same result by specifying certain settings when creating them, but in some cases the serializer may not be available from the user code, or we may want to ensure this behavior regardless of the serializer settings.

Obsolete Data Contract Serialization Properties

The following properties are now marked as obsolete:

  • the Generate Data Contracts property of the EF Core template 
  • the Do Not Generate Data Contract Attribute extended property of navigation properties in EF Core Model 
  • the WCF Data Contract Attributes property of the DbContext and Data Transfer Object templates 
  • the WCF DataMember Attribute on Navigation Properties property of the DbContext and Data Transfer Object templates 

They are still available in the templates and still work in the same way as before, so that models created in previous Entity Developer versions won’t change their behavior. However, we don’t recommend using them in the future as it’s better to use new serialization properties, described above, instead of the obsolete ones.

JSON Data Types Support in EF Core Models

Entity Framework Core supports arbitrary data types in its providers. Some EF Core providers already offer support for JSON data types for entity properties. Namely, Npgsq supports System.Text.Json (JsonDocument and JsonElement as property types), and Pomelo.EntityFrameworkCore.MySql supports Newtonsoft.Json.Linq (JObject and JToken as property types) in addition to System.Text.Json types.

In future support for these types may be added to other providers, so we have extended the list of supported data types in Entity Developer.

Read-only Properties for Database-generated Columns in EF Core Models

Entity Framework Core models now have two new model settings: Private setter for store generated properties and Constructor parameter.

If you select them and generate an Entity Framework Core model for a Microsoft SQL Server table like this:

CREATE TABLE dbo.Products ( 
   ProductID int IDENTITY (1,1) NOT NULL, 
   QtyAvailable smallint, 
   UnitPrice money, 
   InventoryValue AS QtyAvailable * UnitPrice 
)) 

The following code will be generated for the corresponding entity:

     public partial class Product { 
         public Product(int productId, int? inventoryValue) { 
            this.ProductId = productId; 
            this.InventoryValue = inventoryValue; 
        } 
         public int ProductId { get; private set; } 
         public short? QtyAvailable { get; set; } 
         public decimal? UnitPrice { get; set; } 
         public int? InventoryValue { get; private set; } 
    } 

Previously you could achieve this only by specifying Setter Modifier = Private and Constructor Parameter = True for the corresponding properties in the model manually, which could take a lot of time.

Improvements of Standalone Entity Developer and Console Entity Developer

Many of our users use the standalone version of Entity Developer – either because it has less limitations and issues than a full-featured Visual Studio or because they use other IDEs, like Microsoft Visual Studio Code or JetBrains Rider.

Standalone Entity Developer has convenient tools for code generation, but when there were warnings in the model, Entity Developer always displayed a message about these warnings when generating code, and the users could not disable it. However, in some cases warnings cannot be fixed or the users prefer not to fix them, so we have added an ability to disable this message. We hope that this makes code generation in Standalone Entity Developer more convenient.

Console Entity Developer was created not so long ago, only last year, but it already has a number of users, who find it suitable for their use cases. We have added new options –ContextNamespace and –DefaultNamespace to its Create-Model command to allow users tweak generation more flexibly.

Conclusion

This is not a complete list of Entity Developer 6.11 improvements. You can find a complete revision history here. You are welcome to try the new version and leave feedback, because your feedback helps us make Entity Developer better with each new version, and many our new features are introduced because of it.

Leave a Comment