gpt4 book ai didi

c# - N休眠: TINYINT instead of geometry

转载 作者:行者123 更新时间:2023-11-30 15:08:21 24 4
gpt4 key购买 nike

我正在使用 NHibernate 开发一个 C# 项目,我将 fluant-nhibernate 与 autoMapping 结合使用:

        FluentConfiguration configuration = Fluently.Configure()
.Database(databaseConfig)
.Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Entity>(mappingConfiguration).Conventions.Add<GeometryTypeConvention>()));

我有一个具有 IGeometry 属性的类,我已经使用自约定类型配置了自动映射:

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 是正确的。

最佳答案

我遇到了同样的问题,我是这样解决的(使用地理而不是几何,但非常相似):

首先(此步骤是可选的),因为我需要使用 WGS84 坐标,所以我创建了以下类型:

public class Wgs84GeographyType : MsSql2008GeographyType
{
protected override void SetDefaultSRID(GeoAPI.Geometries.IGeometry geometry)
{
geometry.SRID = 4326;
}
}

然后我创建了一个与您的有点相似的约定,但指定了“CustomSqlType”方法:

public class Wgs84GeographyTypeConvention : IPropertyConvention
{
public void Apply(IPropertyInstance instance)
{
if (typeof(IGeometry).IsAssignableFrom(instance.Property.PropertyType))
{
instance.CustomType(typeof(Wgs84GeographyType));
instance.CustomSqlType("GEOGRAPHY");
}
}
}

之后模式生成应该可以正常工作。

关于c# - N休眠: TINYINT instead of geometry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5678539/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com