【问题标题】:NHibernate.Spatial.MySQL: Null geometries and "No persister for: GeoAPI.Geometries.IGeometry" errorNHibernate.Spatial.MySQL:空几何和“没有持久性:GeoAPI.Geometries.IGeometry”错误
【发布时间】:2016-04-24 23:55:32
【问题描述】:

我正在尝试使用 NHibernate.Spatial.MySQL(版本 4.0.4.4001)创建一个简单的演示解决方案。解决方案在这里:https://github.com/andrerav/NHibernate.Spatial.MySql.Demo

映射似乎至少对插入有效——DemoDataImport 项目能够读取 GeoJSON 文件,并将几何图形插入数据库,我可以使用 MySQL Workbench 验证结果。

但是,如果我查询数据,几何图形总是以空值显示。此外,如果我执行这样的查询:

var municipalities = SessionManager.Session.Query<Municipality>()
                        .Where(m => m.Area.Within(county.Area)).ToList();

我收到一个异常,上面写着“没有持久性:GeoAPI.Geometry.IGeometry”。

有什么想法可能是错的吗?

要运行该解决方案,首先使用用户名/密码 mysqldemo/mysqldemo 创建一个名为 mysqldemo 的 mysql 数据库(mysql 5.7 或更新版本)。 DemoDataImport 项目会将geojson 数据转储到数据库中,DemoQueryUtil 项目可用于执行查询。

映射:

public class Municipality
{
    public virtual int Id { get; set; }
    public virtual County County { get; set; }
    public virtual string Name { get; set; }
    public virtual int MunicipalityNo { get; set; }
    public virtual IGeometry Area { get; set; }
}

public class MunicipalityMap : ClassMap<Municipality>
{
    public MunicipalityMap()
    {
        ImportType<IGeometry>();
        Id(x => x.Id);
        Map(x => x.Name);
        Map(x => x.MunicipalityNo);
        Map(x => x.Area).CustomType<MySQLGeometryType>();
        References(x => x.County).Nullable();
    }
}

public class County
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual int CountyNo { get; set; }
    public virtual IGeometry Area { get; set; }
    public virtual List<Municipality> Municipalities { get; set; }

}

public class CountyMap : ClassMap<County>
{
    public CountyMap()
    {
        ImportType<IGeometry>();
        Id(x => x.Id);
        Map(x => x.Name);
        Map(x => x.CountyNo);
        Map(x => x.Area).CustomType<MySQLGeometryType>();
    }
}

配置:

    public static void Configure(bool generateTables = false)
    {
        var cfg = Fluently.Configure()
            .Database(FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard
            .ConnectionString(c => c.FromConnectionStringWithKey("MySQL"))
            .Driver<MySqlDataDriver>()
            .ShowSql()
            .Dialect<MySQLSpatialDialect>())
            .Mappings(x => x.FluentMappings.AddFromAssemblyOf<MunicipalityMap>())
            .BuildConfiguration();

        cfg.AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg));

        if (generateTables)
        {
            var exporter = new SchemaExport(cfg);
            exporter.Drop(false, true);
            exporter.Create(true, true);
        }

        SessionManager.SessionFactory = cfg.BuildSessionFactory();

    }

查询示例:

var county = SessionManager.Session.Query<County>().First();

【问题讨论】:

  • 在有人投入大量时间之前;我找到了根本原因。 MySQL 5.7 引入了一些与 NHibernate.Spatial.MySQL 根本不兼容的更改。我已经编写了一个概念性修复程序,并将很快提交并在 NuGet 上发布。发生这种情况时,我将在这篇文章中添加一个答案,其中包含有关如何使用新方言的说明。

标签: mysql nhibernate fluent-nhibernate mysql-spatial


【解决方案1】:

这个问题是由于NHibernate.Spatial.MySQL 中缺乏对 MySQL 5.7 的支持。我在NHibernate.Spatial.MySQL 的预发布版本中添加了一个新的MySQL57SpatialDialect,它解决了这个问题。

【讨论】:

    猜你喜欢
    • 2017-11-18
    • 1970-01-01
    • 2011-05-14
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    • 2022-11-20
    • 1970-01-01
    相关资源
    最近更新 更多