NHibernate:TINYINT 而不是几何
我正在使用 NHibernate 开发一个 C# 项目,我使用 fluant-nhibernate 和 autoMapping :
FluentConfiguration configuration = Fluently.Configure()
.Database(databaseConfig)
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Entity>(mappingConfiguration).Conventions.Add<GeometryTypeConvention>()));
我有一个具有 IGeometry 属性的类,我已经使用 self Convention 类型配置了自动映射:
public class GeometryTypeConvention : IUserTypeConvention
{
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
criteria.Expect(p => p.Property.PropertyType == typeof (IGeometry));
}
public void Apply(IPropertyInstance instance)
{
instance.CustomType(typeof(MsSql2008GeometryType));
}
}
当我更新架构时,会创建数据库,但所有几何图形类中的属性设置为 TINYINT 列。
我在 上看到了几乎相同的问题http://www.klopfenstein.net/lorenz.aspx/null-geometry-values-in-nhibernate-spatial-for-mssql2008,但我使用的文件MsSql2008GeometryType.cs是正确的。
I'm working on a C# project using NHibernate, I use fluant-nhibernate with autoMapping :
FluentConfiguration configuration = Fluently.Configure()
.Database(databaseConfig)
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Entity>(mappingConfiguration).Conventions.Add<GeometryTypeConvention>()));
I have a classes with IGeometry properties, I have configured automapping with a self Convention type :
public class GeometryTypeConvention : IUserTypeConvention
{
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
criteria.Expect(p => p.Property.PropertyType == typeof (IGeometry));
}
public void Apply(IPropertyInstance instance)
{
instance.CustomType(typeof(MsSql2008GeometryType));
}
}
When I update the schema, the database is created but all Geometry properties in classes are set as TINYINT columns.
I've seen almost the same problem on http://www.klopfenstein.net/lorenz.aspx/null-geometry-values-in-nhibernate-spatial-for-mssql2008, but the file MsSql2008GeometryType.cs I use is correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,我用这种方式解决了它(使用地理而不是几何,但它非常相似):
首先(此步骤是可选的),并且因为我需要使用 WGS84 坐标,所以我创建了以下类型:
然后我创建了一个与您的约定类似的约定,但指定了“CustomSqlType”方法:
之后模式生成应该可以正常工作,没有任何问题。
I had the same problem, and I solved it this way (using geography instead of geometry, but it's very similar):
First (this step is optional), and because I was required to work with WGS84 coordinates, I created the following type:
Then I created a convention somehow similar to yours, but with the "CustomSqlType" method specified:
Afterwards the schema generation should work without any issue.
您应该使用 SpatialAuxiliaryDatabaseObject 才能正确生成空间相关架构。使用 Fluent NHibernate,这看起来像:
另外,在数据库配置中设置方言:
You should use
SpatialAuxiliaryDatabaseObject
in order to properly generate spatial related schema. Using Fluent NHibernate, this would look like:Also, set the dialect in the database configuration: