Table of Contents

2.1 Release Notes

Version 2.1.0 of the Npgsql Entity Framework Core provider has been released and is available on nuget. This version works with version 2.1.0 of Entity Framework Core, and contains some new Npgsql features as well.

Thanks to @rwasef1830 and @austindrenski for their valuable contributions.

New Features

Aside from general EF Core features new in 2.1.0, the Npgsql provider contains the following major new features:

Improved Spatial Support (PostGIS)

Previous versions have allowed basic usage of PostGIS's spatial types via built-in Npgsql types such as NpgsqlPoint, NpgsqlLineString, etc. These types were limited in many ways, and no operation translation was supported. If you want to calculate, say, the distance between two points, you had to drop down to raw SQL.

No more! Thanks to a new plugin infrastructure, the EF Core provider now has full-class support for PostGIS. You can now use the NetTopologySuite spatial library to map PostGIS types - NetTopologySuite's types are more complete, and best of all, the provider knows how to translate its operations to SQL. This allows you to write the following code:

var nearbyCities = context.Cities.Where(c => c.Location.Distance(somePoint) < 100);

See the full documentation for more information.

Thanks to @YohDeadfall for implementing support for this at the ADO level.

PostgreSQL has a powerful feature for efficient natural-language search across multiple columns and tables, see the PostgreSQL docs for more info. The EF Core provider now supports full-text search, allowing you to use .NET functions in your LINQ queries which will get translated to efficient PostgreSQL natural-language search queries.

Read the full documentation for more information.

Many thanks to @rwasef1830 for contributing this feature.

NodaTime date/time support

NodaTime is a powerful alternative to .NET's built-in date/time types, such as DateTime. The built-in types are flawed in many ways: they have problematic support for timezones, don't have a date-only or time-only types, and promote problematic programming but not making the right distinctions. If your application handles dates and times in anything but the most basic way, you should seriously consider using NodaTime. To learn more read this blog post by Jon Skeet.

Thanks to a new plugin infrastructure, it is now possible to set up the EF Core provider to use NodaTime's types instead of the built-in .NET ones; instead of having DateTime properties on your entities, you can now have Instant properties instead.

See the full documentation for more information.

PostgreSQL 10 IDENTITY columns

PostgreSQL 10 introduced a new IDENTITY column as an alternative to traditional SERIAL columns, and these are now supported by the EF Core provider. IDENTITY columns conform to the SQL standard and are in general safer than SERIAL columns, read this blog post for more info. It's recommended that all new projects use IDENTITY, but Npgsql even provides seamless migration of your existing SERIAL-based model!.

Read the full documentation for more information.

Enum support

It is now possible to map your CLR enums to native PostgreSQL enums. This is a unique PostgreSQL feature that provides the best of both worlds: the enum is internally stored in the database as a number (minimal storage), but is handled like a string (more usable, no need to remember numeric values) and has type safety.

See the full documentation for more information.

Range support

PostgreSQL supports native range types, which allow you to represent ranges of dates, ints and other data types in a single column. You can then efficiently perform queries on these types from LINQ, e.g. select all rows where a given date falls in the row's date range.

See the full documentation for more information.

Many thanks to @austindrenski for contributing the operation translations.

Other notable features

  • Several improvements have been made to the way arrays are mapped. For example, you can now map List<T> to PostgreSQL array (previously only T[] was supported) (#392). In addition, change tracking now works for arrays, so EF Core will automatically detect when you change an element's array and will update the corresponding database column when saving.
  • PostgreSQL's built-in range types can now be mapped (#63), head over to the PostgreSQL docs to find out more about range types. Note that user-defined range types are not supported, if you're interested let us know at #329.
  • Properties of type char are now supported and will be mapped to character(1) in PostgreSQL (#374).
  • Identifiers in generated SQL will only be quoted if needed (#327). This should make it much easier to read.
  • You can now use client certificate authentication and provide a server certificate validation callback (#270). See the doc for usage instructions.
  • Added support for PostgreSQL 10 sequences with type int and smallint (#301).
  • You can now specify the tablespace when creating your databases (#332).

Here's the full list of issues. Please report any problems on https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL.

Breaking changes

Caution

The provider's classes have been moved from the namespace Microsoft.EntityFrameworkCore to Npgsql.EntityFrameworkCore.PostgreSQL. As a result, any migrations already generated in your project (as well as the mode snapshot) will have to be manually updated to use the new namespace. You will need to add using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata to all the relevant files.

  • Columns of type timestamp with time zone/timestamptz will now be scaffolded as DateTime properties, and not DateTimeOffset properties. The general use of timestamp with time zone/timestamptz is discouraged (this type does not store the timezone in the database), consider using timestamp without time zone/timestamp instead.
  • If you're specifying index methods with ForNpgsqlHasMethod(), then you will have to fix migrations which generate those indexes. In these migrations, you will find code such as .Annotation("Npgsql:Npgsql:IndexMethod", "gin"). You must remove the extra Npgsql:, leaving .Annotation("Npgsql:IndexMethod", "gin").
  • Specifying versions when specifying PostgreSQL extensions on your model is no longer supported - this was a very rarely-used feature which interfered with extension scaffolding.
  • If you're still referencing the nuget package Npgsql.EntityFrameworkCore.PostgreSQL.Design, please remove it - it's no longer needed or up to date.

Contributors

Thank you very much to the following people who have contributed to the individual 2.1.x. releases.

Milestone 2.1.2

Contributor Assigned issues
@roji 6
@austindrenski 3
@rwasef1830 1

Milestone 2.1.11

Contributor Assigned issues
@roji 1

Milestone 2.1.1.1

Contributor Assigned issues
@roji 4

Milestone 2.1.1

Contributor Assigned issues
@roji 9

Milestone 2.1.0

Contributor Assigned issues
@roji 24
@austindrenski 1
@rwasef1830 1