Entity Framework Core - EF Core 2.2 - 'Point.Boundary' is of an interface type ('IGeometry')

前端 未结 2 1826
深忆病人
深忆病人 2021-01-05 06:16

I am trying the new functionality with EF Core 2.2. It is based on the following article. \"Announcing Entity Framework Core 2.2\" https://blogs.msdn.microsoft.com/dotnet/20

相关标签:
2条回答
  • 2021-01-05 07:06

    As Kyle pointed out you need to call UseNetTopologySuite(), but I would call it during ConfigureServices like this:

    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services
                .AddEntityFrameworkNpgsql()
                .AddDbContext<MyDBContext>(opt =>
                    opt.UseNpgsql(Configuration.GetConnectionString("MyDBConnection"),
                                    o=>o.UseNetTopologySuite()))
                .BuildServiceProvider();
            ...
        }
        ...
    }
    
    0 讨论(0)
  • 2021-01-05 07:09

    You need to call UseNetTopologySuite(). Example here:

    public class ApplicationDbContext : IdentityDbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
    
        }
    
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            IConfigurationRoot configuration = new ConfigurationBuilder()
               .SetBasePath(Directory.GetCurrentDirectory())
               .AddJsonFile("appsettings.json")
               .Build();
            var connectionString = configuration.GetConnectionString("DefaultConnection");
            optionsBuilder.UseSqlServer(connectionString, opts => opts.UseNetTopologySuite());
        }
        public DbSet<Test> Tests { get; set; }
    }
    
    
    public class Test
    {
        public int Id { get; set; }
        public Point Location { get; set; }
    }
    

    I ran into this problem because I had a if (!optionsBuilder.IsConfigured) around everything in my OnConfiguring. I had to remove this in order to get add-migrations to work.

    0 讨论(0)
提交回复
热议问题