Closed leonkosak closed 4 years ago
Does it work fine if you directly use aspnet core application?
@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.
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:
Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite
package to your domain layer in order to use the Point
and Geometry
types.PostgeSqlDemoDbContextModelCreatingExtensions.cs
as usual.PostgeSqlDemoEntityFrameworkCoreModule
in the efcore project:
Configure<AbpDbContextOptions>(options =>
{
options.UsePostgreSql(builder => builder.UseNetTopologySuite());
});
PostgeSqlDemoMigrationsDbContextFactory
in the dbmigrations project:
var builder = new DbContextOptionsBuilder<PostgeSqlDemoMigrationsDbContext>()
.UseNpgsql(configuration.GetConnectionString("Default"), opts => opts.UseNetTopologySuite());
Create a new migration (you probably need to delete the initial migration since it was for the sql server) and update the database.
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.
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),
vsLocation = 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.