I'm trying to map a dictionary where the key is an enumeration and the 
value is an entity.  Per the attached files. I'm running into a problem 
where nhibernate isnt inserting the key field of the mapping in the child 
record.  What am I doing wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Attachment: Mappings.hbm.xml
Description: XML document

using System.Collections.Generic;

namespace NHMapTest
{
    public class Resolution
    {
        public virtual int Id { get; set; }
        public virtual Conflict Conflict { get; set; }
    }
    public class Conflict
    {
        public Conflict()
        {
            Resolutions = new Dictionary<ConflictEnd, Resolution>();
        }
        public virtual long Id { get; set; }
        public virtual IDictionary<ConflictEnd, Resolution> Resolutions { get; protected set; }

        public virtual void AddResolution(ConflictEnd end, Resolution res)
        {
            res.Conflict = this;
            Resolutions[end] = res;
        }
    }
    public enum ConflictEnd { Left,Right}
}
using System;
using System.CodeDom;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Tool.hbm2ddl;
using NUnit.Framework;

namespace NHMapTest
{
    [TestFixture]
    public class Class1
    {
        [Test]
        public void CanDo()
        {
            var cfg = new DbConf();
            new SchemaExport(cfg).Execute(true,true, false);

            using (var sf = cfg.BuildSessionFactory())
            {
                using (var s = sf.OpenSession())
                using(var tx = s.BeginTransaction())
                {
                    var cfl = new Conflict ();
                    cfl.AddResolution("left", new Resolution());
                    cfl.AddResolution("right", new Resolution());
                    s.SaveOrUpdate(cfl);
                    s.SaveOrUpdate(cfl.Resolutions["left"]);
                    s.SaveOrUpdate(cfl.Resolutions["right"]);
                    tx.Commit();
                }
            }
        }
    }

    public class DbConf : NHibernate.Cfg.Configuration
    {

        public DbConf()
        {
            this.DataBaseIntegration(db =>
            {
                db.ConnectionStringName = "DefaultConnection";
                db.Dialect<MsSql2008Dialect>();
                db.LogSqlInConsole = true;
                db.LogFormattedSql = true;
            });
            this.AddAssembly(typeof (DbConf).Assembly);
        }
    }
}

Reply via email to