Note that there are some explanatory texts on larger screens.

plurals
  1. POError saving components to database with fluent nHibernate?
    text
    copied!<p>Here is my object and mapping:</p> <pre><code> 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&lt;EMA&gt; EMAs { get; set; } //List all EMAs calculated. public virtual List&lt;SMA&gt; SMAs { get; set; } } public class candleStimMap : ClassMap&lt;candleStim&gt; { public candleStimMap() { Id(x =&gt; x.Id); Map(x =&gt; x.candleNumber); Map(x =&gt; x.date); Map(x =&gt; x.open); Map(x =&gt; x.high); Map(x =&gt; x.low); Map(x =&gt; x.close); HasMany&lt;SMA&gt;(x =&gt; x.SMAs) .Component(c =&gt; { c.Map(x =&gt; x.SimpleMovingAverage); c.Map(x =&gt; x.periods); }).AsSet(); HasMany&lt;EMA&gt;(x =&gt; x.EMAs) .Component(c =&gt; { c.Map(x =&gt; x.ExponentialMovingAverage); c.Map(x =&gt; x.periods); }).AsSet(); Table("candle_Simulation"); } //end public candleStimMap() </code></pre> <p>Here is my current attempt at saving (which fails)</p> <pre><code> 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++; } </code></pre> <p>The error msg:{"Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericSet<code>1[Midas_FOREX_Engine.Indicators.SMA]' to type 'System.Collections.Generic.List</code>1[Midas_FOREX_Engine.Indicators.SMA]'."}</p> <p>So I've got a mismatch of list types. How would I make a list of the NHibernate.Collection.Generic.PersistentGenericSet type and save the values?</p> <p>The only fields Im saving to the database from the SMA-EMA is a decimal of the value and an integer of the number of periods.</p> <p>Thank you!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload