English 中文(简体)
Fluent Nhibernate Way to Map to a Class Property or make a calculate property?
原标题:

I have a class with a bounding box, and I want to have subclasses that set the values of the bounding box, based on their attributes


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);   
}

Is there a way to do this?

问题回答

Though about it, and determined, create an additional logic layer, put it in the layer. Just use NHibernate as the storage layer





相关问题
Does Fluent NHibernate support "trigger-identity"

I posted the question in the Fluent-NHibernate newgroup but so far there has been no answer from the void. Is there a Fluent NHibernate mapping for the NHibernate "trigger-identity" method of ...

automapping nested components naming conventions

Im making the switch from Fluent Mapping to Automapping in my current project. If I have the following domain: public class Matter{ public Client Client{get;set;} } public class Client { ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....

Fluent nHibernate keeps recreating my database, why?

I m trying to convert my data layer from Linq2Sql to nHibernate. I think Xml the configuration in nHibernate is pretty backwards so I m using Fluent. I ve managed to get fluent, add in a repository ...

How to fluent-map this (using fluent nhibernate)?

I have two tables in my database "Styles" and "BannedStyles". They have a reference via the ItemNo. Now styles can be banned per store. So if style x is banned at store Y then its very possible that ...

热门标签