문제

I am using the QuantLib's Date class in a C# project, and this causes some problems when trying to map my Price class to my price table in a mySql database.

The price table has three columns: [id], [date] and [value] and the code looks like this :

//ENTITY
    public class Price{
        public virtual long id { get; protected set; }
        public virtual QuantLib.Date date { get; set; }
        public virtual double value{ get; set; }
    }

//MAPPING
    public PriceMap() {
        Table("price");
        Id(x => x.id, "id");
        Map(x => x.date, "date") // to be completed... ;
        Map(x => x.value, "value");
    }

Is there a way to specify to NHibernate how to map this class to MySQL's Date type, using Fluent NHibernate? Sort of casting it before saving in or retrienving from the db, without having to change the entity's structure.

도움이 되었습니까?

해결책

You have two options

  1. Create a custom type for nhibernate and specify it in the mapping as .CustomType. Therefore you'll have to implement a small interface which does the conversion to and from QuantLib.Date

  2. You simply change the type of the date property to System.DateTime and add another property which read/writes to the date property but uses your QuantLib.Date, pseudocode:

    public QuantLib.Date QDate {
       get{
         // read from this.date and create a new QuantLib.Date
       }
       set{
         // write to this.date
       }
    }
    
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top