我正在尝试使用NHibernate 2.0持久化SortedList <DateTime,double?> . 当项的值(非键)为空时,该项不会持久保存到数据库 .
类片段:
public class TimeSeries{
...
public TimeSeries(){
Data = new SortedList();
}
public virtual IDictionary Data { get; private set; }
...
}
映射片段:
...
<map name="Data" cascade="all" lazy="true" sort="natural" collection-type="sorted-list">
<key column="ID"/>
<index type="Date" column="Period"/>
<element type="double" column="Value" not-null="false"/>
</map>
...
用法片段:
var series = new TimeSeries();
series.Data.Add(new DateTime(2000, 1, 1), 1);
series.Data.Add(new DateTime(2000, 1, 2), null);
series.Data.Add(new DateTime(2000, 1, 3), 3);
repository.Add(series);
第一个和第三个项目是持久的,但不是第二个 . 如果我将double值从空值更改为非null值,则可以保存正常 .
知道如何保存空值吗?我正在使用MySql,数据库模式允许空值 .
谢谢,马库斯