流利的Nhibernate方式映射到类属性或计算属性?

时间:2009-11-13 02:08:13

标签: fluent-nhibernate

我有一个带有边界框的类,我希望有基于其属性设置边界框值的子类


public class LocationBase : BaseEntity
{

    public virtual int Id { get; set; }

    public virtual double North { get; set; }
    public virtual double East { get; set; }
    public virtual double South { get; set; }
    public virtual double West { get; set; }

    public virtual string SpatialReferenceSystemCode { get; set; }

    public LocationBase()
    {
        SpatialReferenceSystemCode = "EPSG:4236";
    }
}

public class LocationGeographicPoint : LocationBase
{

    public virtual double Longitude { get; set; }
    public virtual double Latitude { get; set; }

}

 public class LocationBaseMap : ClassMap<LocationBase>
    {
        public LocationBaseMap()

    {
        Table("Locations");
        Id(x => x.Id).Column("LocationId").GeneratedBy.Increment();
        Map(x => x.North).Not.Nullable();
        Map(x => x.West).Not.Nullable();
        Map(x => x.South).Not.Nullable();
        Map(x => x.East).Not.Nullable();
        Map(x => x.SpatialReferenceSystemCode).Default("EPSG:4326").Nullable();
    }
}

public class LocationGeographicPoint : LocationBase
{

    public virtual double Longitude { get; set; }
    public virtual double Latitude { get; set; }

}

 public class LocationGeographicPointMap : SubclassMap<LocationGeographicPoint>

    {
        public LocationGeographicPointMap() {

        Map(x => x.Latitude).Not.Nullable();
        Map(x => x.Longitude).Not.Nullable();
         Map(x => x.SpatialReferenceSystemCode).Nullable();

     Map(x => x.North).Function(m => m.Latitude);
     Map(x => x.South).Function(m => m.Latitude);     
     Map(x => x.East).Function(m => m. Longitude);
     Map(x => x.West).Function(m => m. Longitude);   
}

有办法做到这一点吗?

1 个答案:

答案 0 :(得分:0)

虽然关于它,并确定,创建一个额外的逻辑层,把它放在图层中。只需使用NHibernate作为存储层