0

ここに私のオブジェクトとマッピングがあります:

 public class candleStim
{
    public virtual int       Id            { get; set; }
    public virtual int       candleNumber  { get; set; } //the number of the candle from the data set, should correspond with number of minutes into testing on 1 min candles
    public virtual DateTime  date          { get; set; }
    public virtual decimal   open          { get; set; }
    public virtual decimal   high          { get; set; }
    public virtual decimal   low           { get; set; }
    public virtual decimal   close         { get; set; }
    public virtual List<EMA> EMAs          { get; set; } //List all EMAs calculated.
    public virtual List<SMA> SMAs          { get; set; }
}

    public class candleStimMap : ClassMap<candleStim>
    {
        public candleStimMap()
        {
            Id(x => x.Id);

            Map(x => x.candleNumber);
            Map(x => x.date);
            Map(x => x.open);
            Map(x => x.high);
            Map(x => x.low);
            Map(x => x.close);



            HasMany<SMA>(x => x.SMAs)
                .Component(c =>
                    {
                        c.Map(x => x.SimpleMovingAverage);
                        c.Map(x => x.periods);
                    }).AsSet();


            HasMany<EMA>(x => x.EMAs)
              .Component(c =>
              {
                  c.Map(x => x.ExponentialMovingAverage);
                  c.Map(x => x.periods);
              }).AsSet();
            Table("candle_Simulation");


        } //end public candleStimMap()

これが私の現在の保存の試みです(失敗します)

     foreach (candleStim c in calculatedCandles)
            {
                using (var session = NHibernateHelper.OpenSession())
                {

                    using (var transaction = session.BeginTransaction())
                    {

                        candleStim cc = new candleStim();
                        cc.date = c.date;
                        cc.open = c.open;
                        cc.high = c.high;
                        cc.low = c.low;
                        cc.close = c.close;

 //The below 2 lines are where the problem arises
//if these are standard objects, no errors show up
                        cc.EMAs = c.EMAs;
                        cc.SMAs = c.SMAs;


                        session.Save(c);
                        transaction.Commit();

                    }

                }
                counter++;

            }

エラーメッセージ: {「'NHibernate.Collection.Generic.PersistentGenericSet 1[Midas_FOREX_Engine.Indicators.SMA]' to type 'System.Collections.Generic.List1[Midas_FOREX_Engine.Indicators.SMA]' 型のオブジェクトをキャストできません。」}

そのため、リストの種類が一致しません。NHibernate.Collection.Generic.PersistentGenericSet 型のリストを作成して値を保存するにはどうすればよいですか?

SMA-EMA からデータベースに保存する唯一のフィールドは、値の 10 進数とピリオド数の整数です。

ありがとうございました!!

4

1 に答える 1