Yeah, the CustomCollectionType doesn't override the
GetElementsCollection, so it just uses the base class implementation
from CollectionType, which just returns all the elements (as
KeyValuePairs of the dictionary, instead of using the dictionary
values). The proper way to fix this is to extend IUserCollectionType
to define this method and have each user type implement the method.
Then the CustomCollectionType can just delegate the call to the user
type, like it does for most of the other methods. It's the actual
user type that should be deciding what the elements are.
In lieu of the above described fix, I changed the
CustomCollectionType.cs file and added an overriden
GetElementsCollection like this:
/// <summary>
/// Returns a reference to the elements in the collection.
/// </summary>
/// <param name="collection">The object that holds the
ICollection.</param>
/// <returns>An ICollection of the Elements(classes) in the
Collection.</returns>
/// <remarks>
/// By default the parameter <c>collection</c> is just cast to
an ICollection. Collections
/// such as Maps and Sets should override this so that the
Elements are returned - not a
/// DictionaryEntry.
/// </remarks>
public override ICollection GetElementsCollection(object
collection)
{
if (collection is IDictionary)
{
return ((IDictionary)collection).Values;
}
return base.GetElementsCollection(collection);
}
This should handle custom dictionaries if they implement the non-
generic IDictionary interface. I just changed this on my local code
and re-build the NHibernate.dll, so I haven't put these changes into
the NHibernate source repository or anything. It seems to do the
trick. My custom dictionaries persist without error after this
change.
Jon.
On Sep 7, 6:07 pm, srf <[EMAIL PROTECTED]> wrote:
> We are on nhibernate 1.2 and have been able to implement our own
> custom list collections but when we tried to implement a custom
> dictionary collection we get the following error:
>
> "Unknown entity class: System.Collections.Generic.KeyValuePair`2
>
> I debugged into it and found when using a custom dictionary it uses
> the base CollectionType class for the dictionary collection and the
> framework ends up call this method in this class:
>
> public virtual ICollection GetElementsCollection(object collection)
> {
> return ((ICollection) collection);
> }
>
> I then debugged it using the standard dictionary and it ended up using
> the MapType class which inherits CollectionType and its method looks
> like this:
>
> public override ICollection GetElementsCollection(object collection)
> {
> return ((IDictionary) collection).Values;
> }
>
> notice the first one returns the collection which is why the error
> about unknow entity class is being raised since it ends up returning a
> collection of key value pairs rather than a collection of objects as
> what the MapType class does.
> So , I how can we somehow get it to use the MapType class since using
> a custom type always forces the use of the CollectionType class. If
> anyone has an example of doing a custom dictionary collection , that
> would be great too.
>
> thanks
>
> scott
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---