Our Blogs

Entity Framework Core 2.0 Gets Better With New Features And Enhancements

August 29, 2017
Entity Framework Core 2.0 Gets Better With New Features And Enhancements
Microsoft has shipped Entity Framework Core 2.0 with plenty of changes. The highlight of the EF Core is that provider APIs has been modified without providing a backward compatibility option. Hence, you will not be able to make use of the EF Core 1.0 and 1.1 providers with EF Core 2.0. Developers should rewrite using the EF Core 2.0 APIs.

Microsoft confirmed that the open source third party providers for MySQL, PostgreSQL, and SQL Compact are updated to target version 2.0. Moreover, in EF Core 2.0, the IDbContextFactory has been marked as obsolete and the relevant tools will call IDesignTimeDbContextFactory class. Microsoft also dropped support for DbContextFactoryOptions class since it wasn't a perfect time to perform content generation.

The EF Core 2.0 has changed the event IDs for messages sent to an ILogger. They are now unique across the EF Core code system. According to Microsoft, the messages follow the standard pattern for structured logging used by the MVC. The core has also changed the Logger categories. Interestingly, the DiagnosticSource events make use of the same event ID names as the appropriate ILogger messages. It is to be noted that the payloads meant for events are derived from EventData.

With EF Core 2.0, you need to provide a name while creating In-memory databases. The purpose of this is to solve business logic problems easily. You should note that the same in-memory database can be shared by several context instances.

Microsoft has dropped support for IsReadOnlyAferSave, IsStoreGeneratedAlways and IsReadOnlyBeforeSave in the latest version of EF Core that is exposed by the IProperty interface.These are replaced by the AfterSaveBehavior and BeforeSaveBehavior properties.

Microsoft has deleted dependent entities in the EF Core 2.0. However, the behavior is only applicable to entities that are being monitored by the context. Moreover, the foreign key properties in dependent entities are set to null in Core 2.0. If you make use of the EF to create the database, the core package will automatically setup things for you. You will also find new option named ClientSetNull.

Microsoft also introduced a new ClientSetNull behavior as the default for optional relationships to track entities and restrict behavior for databases designed using the EF Core. Furthermore, the Microsoft.EntityFrameworkCore.Relational.Design package has been replaced with the Microsoft.EntityFrameworkCore.Relational and Microsoft.EntityFrameworkCore.Design packages.