abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.86k stars 3.43k forks source link

EF Core (3.1) Spatial Data issue for Postgres 12.2 #3885

Closed leonkosak closed 4 years ago

leonkosak commented 4 years ago

I don-' know if this is EF Core-related issue or has to do something with abp.

I have dockerized Postgres 12.2 with PostGis (v3.0.1): https://registry.hub.docker.com/r/postgis/postgis/

The desired database also has "assigned" Postgis extension, so no problem here.

abp v2.6.2 (with EF Core 3.1) I have table with "Point" data type (NetTopologySuite).

I followed:

https://docs.microsoft.com/en-us/ef/core/modeling/spatial https://www.npgsql.org/efcore/mapping/nts.html

and always delete Migrations folder. o => o.UseNetTopologySuite() is also present in my abp code (and Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite package is installed).

I also tried with and without .HasColumnType("geography (point)") (and "geometry), but the only difference in snapshot is:

Location = table.Column<Point>(nullable: true), vs Location = table.Column<Point>(type: "geometry", nullable: true),

Generating migration is not an issue. When running Migrator (console app), there is always error message:

The property 'ConcentratorInstance.Location' is of type 'Point' which is not supported by current database provider. Either change the property CLR type or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

I have no idea if this is related directly to EF Core or I have to configure something in abp that this issue won't be present anymore.

Does anyone tried using EF Core Spatial Data on Postgres? Thank you.

realLiangshiwei commented 4 years ago

Does it work fine if you directly use aspnet core application?

leonkosak commented 4 years ago

@liangshiw, Yes. I created basic .NET Core 3.1 console app with EF Core 3.1.3 and followed documentation on links in my first post. I tun migration (Update-Database) on new database (with "assigned" postgis extensions). Everything went perfectly without any warnings or issues. I tried this scenario on the same SQL as I tried with abp.

I would really like to use this functionality if possible. Thank you.

hikalkan commented 4 years ago

I tried. I did all but stuck with the portgresql installation (I am not postgresql expert). You can probably handle it.

I prepared a sample project: https://github.com/abpframework/abp-samples/tree/master/PostgeSqlDemo

Important points:

Create a new migration (you probably need to delete the initial migration since it was for the sql server) and update the database.

leonkosak commented 4 years ago

Well, I didn't know that .UsePostgres (in xyzEntityFrameworkCoreModule.cs) method should also take a parameter. I will highlight this in my notes. Thank you.

P.S.: @hikalkan, use docker images for such scenarios (Postgres or Postgis is Linux-container only). :) Using SQL in Docker is of course highly not-recommended in production environments, but for development end testing is super convenient.