Hi Ricardo

Thanks for your reply. I'm afraid i havn't made any progress yet. I
tried to change the signature of the Data property with two different
implementations. In the first I use a private field, so I'm able to
initialse the field in the constructor. In the second I use an auto-
implemented property (which I think is the one that u suggest).
However both of these of these implementations gives me the
NullReferenceException when calling
Configuration.BuildSessionFactory().

Does anyone have a code example of how to map a SortedList<,>?

Thank you

TestEntity implementation 1:

namespace Domain
{
    public class TestEntity
    {
        private SortedList<DateTime, string> _data;

        public TestEntity()
        {
            _data = new SortedList<DateTime, string>();
        }

        public virtual Guid Id { get; set; }

        public virtual IDictionary<DateTime, string> Data
        {
            get { return _data; }
            set
            {
                _data = value is SortedList<DateTime, string>
                    ? (SortedList<DateTime, string>)value
                    : new SortedList<DateTime, string>(value);
            }
        }
    }
}

TestEntity implementation 2:
namespace LiveBall.Domain.Participant
{
    public class TestEntity
    {
        public TestEntity()
        { }

        public virtual Guid Id { get; set; }

        public virtual IDictionary<DateTime, string> Data
        {
            get;
            set;
        }
    }
}

TestEntity.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Domain" namespace="Domain">
  <class name="TestEntity">
    <id name="Id">
      <generator class="guid" />
    </id>
    <map name="Data" sort="natural">
      <key column="EntityId" />
      <index column="time" type="DateTime" />
      <element column="value" type="String" />
    </map>
  </class>
</hibernate-mapping>

On Mar 3, 11:07 pm, Ricardo Peres <[email protected]> wrote:
> Map the Data property through an interface, such as:
>
> public virtual IDictionary<DateTime, string> Data
> {
>     get;
>     set;
>
>
>
> }
> On Saturday, March 3, 2012 9:40:12 PM UTC, Arcreme wrote:
>
> > I am trying to map the following SortedList:
>
> > ...
> > private SortedList<DateTime, string> _data;
> > public virtual SortedList<DateTime, string> Data
> > {
> >     get { return _data; }
> >     set { _data = value; }
> > }
>
> > ...
> > <map name="Data" sort="natural">
> >   <key column="EntityId" />
> >   <index column="time" type="DateTime" />
> >   <element column="value" type="String" />
> > </map>
> > ...
>
> > However when I try to create a session factory using
> > Configuration.BuildSessionFactory() I get a NullReferenceException:
>
> > --NullReferenceException
> > at NHibernate.Mapping.Map.get_CollectionType() in d:\CSharp\NH\NH
> > \nhibernate\src\NHibernate\Mapping\Map.cs: line 33
>
> > If I omit the sort attribute (which I belive I shouldn't according to
> > the manual) in the map element i get a
> > NHibernate.PropertyAccessException:
>
> > System.InvalidCastException : Unable to cast object of type
> > 'NHibernate.Collection.Generic.PersistentGenericMap`2[System.DateTime,Syste­m.String]'
>
> > to type
> > 'System.Collections.Generic.SortedList`2[System.DateTime,System.String]'.
>
> > I also to have the sort attribute to point to a implementation of the
> > IComparer interface, but I still get the NullReferenceException.
>
> > Any ideas on how to succesfully map a SortedList?
>
> > Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to