- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
给定以下模型:
using NetTopologySuite.Geometries;
public class bounding_box
{
public virtual int id { get; protected set; }
public virtual Polygon area { get; set; }
}
在使用 Fluent Nhibernate 生成数据库模式时,如何将 area
属性自动映射到 area geometry(Polygon)
列?请注意,我不关心能否使用 NHibernate 读取/更新几何列,因为我将在我的代码中使用 GDAL。
我知道我可以通过实现手动覆盖来做到这一点,即:
public class bounding_boxMappingOverrride : IAutoMappingOverride<bounding_box>
{
public void Override(AutoMapping<bounding_box> mapping)
{
mapping.Map(x => x.area)
.CustomSqlType("geometry(Polygon)");
}
}
但是,我有很多包含几何列的表,因此我更希望能够指定自定义类型映射。
出于某种原因,
area
属性永远不会被以下属性约定拦截:
public class PostgisTypesConvention : IPropertyConvention
{
public void Apply(IPropertyInstance instance)
{
if (instance.Type == typeof(Polygon))
{
instance.CustomSqlType("geometry(Polygon)"); // Never reached
}
}
}
如果我使用
GeoAPI.Geometries.IPolygon
而不是
NetTopologySuite.Geometries.Polygon
,我会遇到同样的问题...
最佳答案
我终于能够通过定义自定义 UserTypeConvention
来解决这个问题,即:
using NetTopologySuite.Geometries;
using NHibernate.Spatial.Type;
public class PostGisPolygonUserTypeConvention : UserTypeConvention<PostGisGeometryType>
{
public override void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
criteria.Expect(c => c.Type == typeof(Polygon));
}
public override void Apply(IPropertyInstance instance)
{
// Have to set CustomType to be able to read/write rows using NHibernate
instance.CustomType<PostGisGeometryType>();
// Have to set CustomSqlType to generate correct SQL schema
instance.CustomSqlType("geometry(Polygon)");
}
}
同样的原理也可以用来为其他几何创建UserTypeConventions
,比如Point
, LineString
, MultiPoint
等
关于c# - Fluent NHibernate automap PostGIS 几何类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29939528/
我正在为类 A 使用 AutoMapper和 B .该项目是一个 .Net 核心项目 enabled . public class A { public ClassX? X { get; se
这是我遇到的错误 CookBook.Tests.CategoryRepository_Fixture.Can_update_category: FluentNHibernate.Cfg.FluentC
我有一个关于使用 PrimaryKeyNamingConvention 的问题 假设有以下类: public class banco { [Required] public virtu
我有一个与 SQLAlchemy 一起使用的预先存在的数据库,因此我使用 automap 从数据库中获取模型。向这些类添加方法的最佳方法是什么?例如,对于 User 类,我想添加验证密码等方法。另外,
我是 SQLAlchemy(通常是 ORM)的新手,我正在尝试将现有的应用程序转移到 SQLAlchemy,以便我们可以将一些代码复杂性从当前现有(并且更新乏味)查询转移到 Python。不幸的是,我
我正在使用具有自动映射功能的 SQL Alchemy v(0.9.1)。这允许我自动创建类和关系。 http://docs.sqlalchemy.org/en/rel_0_9/orm/extensio
鉴于以下类(class): public class Address : Place { public virtual string Street { get; set; } publ
我是 Fluent 的初学者,我遇到了一个问题,这可能是我自己的错。 我有一个包含 3 个类的命名空间。实体、实体版本和属性。类之间不涉及继承。 我尝试只映射 Entity 类,但实际情况是命名空间中
我正在使用 fluent nhibernate 来映射以下模型: public abstract class BasePermission : Entity { public abstract
我正在尝试 Fluent NHibernate 的自动映射功能,当我尝试移动时,构建 SessionFactory 时使用显式 ClassMap 配置的相同代码失败它自动映射。 代码如下: publi
NHibernate 似乎不能自动映射一个实体中给定类型的多个 IList。 考虑以下两个实体(基于 Fluent NHibernate 源代码中包含的 Examples.FirstProject 示
我在使用 CultureInfo 属性自动映射实体时遇到问题,当我尝试构建 SessionFactory 时,它抛出异常并出现以下错误:“来自表 ExampleClass 的关联引用了一个未映射的类:
我有两张 table ,地点和设施 他们映射到两个类, public Location : Entity { //properties } public Facility : Entity {
我是 NHibernate 和流利的 nhibernate 新手。我在唯一约束和 nhibernate 映射方面遇到了一些问题。 我有领域模型的以下部分。 public class Batch {
当数据对象模型发生变化(向类添加新属性)时,流畅的自动映射是否有一种方法可以改变模式,目前它只会删除并重新创建数据库模式,这将丢失数据库中的所有数据.它可以使用 Alter table 而不是 dro
给定以下模型: using NetTopologySuite.Geometries; public class bounding_box { public virtual int id { g
我也是 NHibernate 和 FNH 的新手。我熟悉 ORM,并决定看看所有关于这个特定 ORM 的讨论主要是因为生产力的提高。在这一点上,我认为我的时间最好花在其他东西上,但我不想让它打败我,我
我需要做的是我的抽象页面类的自动映射子类。我需要在我获得运行时(在初始化阶段)的程序集列表中找到它们。我没有对我的映射程序集中的程序集的任何引用。 我的页面类看起来像这样: public abstra
有人可以帮忙吗,我如何指示 automap 为 not-null 一个专栏? public class Paper : Entity { public Paper() { }
如果使用 Fluent NHibernate,是否可以自动映射大多数类,但指定应该使用常规 fluent API 映射几个特定类而不是自动映射?如果是这样,任何人都可以指点我一些示例代码来展示如何做到
我是一名优秀的程序员,十分优秀!