1

I`m trying to map this class:

using NetTopologySuite.Geometries;
using System.Collections.Generic;

namespace Project.API.Models
{
    public class Geo
    {
        public int Id { get; set; }
        public IEnumerable<Geometry> Geometries{ get; set; }
    }
}

But when I try to add a new migration I'm having this error:

The property 'Geometry.UserData' could not be mapped, because it is of type 'object' which is not a supported primitive type or a valid entity type...

Doing some research (https://www.npgsql.org/efcore/mapping/nts.html) I found that I need to use:

services.AddDbContext<DataContext>(x => x.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"), o => o.UseNetTopologySuite()));

instead of

services.AddDbContext<DataContext>(x => x.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));

But adding the o => o.UseNetTopologySuite() I have the error:

'NpgsqlDbContextOptionsBuilder' does not contain a definition for 'UseNetTopologySuite'

I think this i related to version issues but the versions that I'm using are exactly as suggested in this issue on github (https://github.com/npgsql/efcore.pg/issues/1024).

NuGet:

enter image description here

Raul
  • 167
  • 9

1 Answers1

3

As the documentation says, you need to reference the Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite package. Also note that if you use EF Core 2.2, you will have to use NetTopologySuite 1.15.x and not 2.0.0; the latter will only work with EF Core 3.0/3.1.

Shay Rojansky
  • 15,357
  • 2
  • 40
  • 69
  • I was using NetTopologySuite 1.15.x but I couldn't reference the Coordinate class. It looks like it's only avaible at 2.0.0. I may doing something very dumb this is my first try at NetTopologySuite. I'm trying to create an Polygon, and for that I need to pass the coordinates array. – Raul Dec 19 '19 at 15:35
  • Where you maybe missing a using for the using GeoAPI.Geometries namespace? Take a look at [the NetTopologySuite samples](https://github.com/synhershko/nettopologysuite/blob/29e6b41711445552aff1dc012dfb1d5849dc948a/NetTopologySuite.Samples.Console/SimpleTests/Geometries/PolygonSamples.cs). If you're still running into issues you can open another question with the full information. – Shay Rojansky Dec 27 '19 at 14:25