【问题标题】:dotnet core database first using NetTopologySuitedotnet core 数据库首先使用 NetTopologySuite
【发布时间】:2023-03-27 05:58:01
【问题描述】:

我最近升级到了最新版本的 EntityFrameworkCore.PostgreSQL,但空间数据似乎不起作用,因为他们现在使用 NetTopologySuite 参见here

要设置 NetTopologySuite 插件,请添加 Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite nuget 到您的 项目。然后,对您的 UseNpgsql() 进行以下修改 行:

我使用dotnet ef dbcontext scaffold 命令

dotnet ef dbcontext scaffold "MyConnectionString" Npgsql.EntityFrameworkCore.PostgreSQL

但是,scaffold 命令似乎没有使用 NetTopologySuite 映射。我仍然收到以下错误

Could not find type mapping for column 'public.behaviour.coord' with data type 'geometry(Point)'. Skipping column.

如何使用 NetTopologySuite

搭建我的数据库

【问题讨论】:

标签: c# postgresql .net-core nettopologysuite


【解决方案1】:

我也遇到过类似的问题,在更新 postgre 库后,我不得不删除迁移文件并重新生成新文件

【讨论】:

    【解决方案2】:
    public class EFDesignTimeService : IDesignTimeServices
    {
        public void ConfigureDesignTimeServices(IServiceCollection services)
        {
            new EntityFrameworkRelationalServicesBuilder(services).TryAddProviderSpecificServices(x =>
            {
                x.TryAddSingleton<INpgsqlOptions, NpgsqlOptions>(p =>
                {
                    var dbOption = new DbContextOptionsBuilder()
                        .UseNpgsql("connection string",
                            ob => ob.UseNodaTime().UseNetTopologySuite()).Options;
                    var npgOptions = new NpgsqlOptions();
                    npgOptions.Initialize(dbOption);
                    return npgOptions;
                });
            });
        }
    }
    

    【讨论】:

      【解决方案3】:

      我使用的是geometry(Point, 4326) 类型 我不得不将类型更改为几何体

      ALTER COLUMN coord TYPE geometry;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-21
        • 1970-01-01
        相关资源
        最近更新 更多