开发者

Dictionary won't persist with NHibernate 3.0

I have the following entity:

public class Alert
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual IDictionary<CxChannel, string> Messages { get; set; }
}

public enum CxChannel
{
    Message,
    Email
}

and following mapping:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Entities.Alert, Entities" table="alert">
  <id name="Id" type="int" unsaved-value="0" access="property">
    <generator class="identity"/>
  </id>

  <property name="Nam开发者_如何学Goe" column="name"/>
    <map name="Messages" table="alert_message" cascade="all">
      <key column="alert_id"/>
      <index column="channel" type="Entities.CxChannel, Entities"/>
      <element column="message" type="System.String"/>
    </map>
  </class>
</hibernate-mapping>

The problem is that when I save an alert entity, Messages dictionary is not persisted to database. As a matter of fact my code looks like the code Oren used in his blog post: http://ayende.com/Blog/archive/2009/06/03/nhibernate-mapping-ndash-ltmapgt.aspx

Has anyone experienced same issue?


Verify that your channel column is an integer in your schema as the CxChannel enum will be mapped as 0 (for Message) and 1 (for email). I just pasted your code and mappings into a console project, used new SchemaExport(cfg).Execute(false, true, false), and successfully inserted rows into the generated database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜