mysql - NHibernate.Spatial.MySQL : Null geometries and "No persister for: GeoAPI.Geometries.IGeometry" error

标签 mysql nhibernate fluent-nhibernate mysql-spatial

我正在尝试使用 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.Geometries.IGeometry”。

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

要运行该解决方案,首先创建一个名为 mysqldemo 的 mysql 数据库(mysql 5.7 或更高版本),用户名/密码为 mysqldemo/mysqldemo。 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();

最佳答案

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

关于mysql - NHibernate.Spatial.MySQL : Null geometries and "No persister for: GeoAPI.Geometries.IGeometry" error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36830256/

相关文章:

mysql - 拉拉维尔 : checking the time by whereBetween clause

mysql - 优化这个非常慢的 MySQL 查询

c# - 找不到字段 : 'NHibernate.NHibernateUtil.String'

fluent-nhibernate - Fluent Nhibernate 域驱动设计

mysql - MySQL 中的更改数据捕获

php - 如何将数据从 PHP 插入到 MySQL DB

c# - Orchard 自定义模块 - NHibernate 选择的模型 - 需要虚拟属性

nhibernate - 如何配置 FluentNHibernate 不覆盖现有的 SQLite 数据库文件?

asp.net-mvc - NHibernate,依赖注入(inject)。正确关闭ISession

nhibernate - Fluent NHibernate 以智能方式映射 IDictionary<string, class>