The object-relational mapper for .NET

How to

This page is converted from the old nhforge.org Wiki. First published by: ashern on 07-14-2011, Last revision by: ashern on 07-14-2011

ConventionModelMapper & .net 4 ISet<>

Note: This information is mosly obsolete as it applies to NHibernate 3 only. If you run on .Net 4 you should use NHibernate 4, which has built-in support for .Net 4's ISet<>.

For anyone using José's Net4CollectionTypeFactory to enable native ISet<> usage, here's how to get the convention mapper to recognize your ISet<> properties as type Set rather than Bag (code courtesy JFR):

In your mapping


Function implementation

private static bool IsSetFieldType(MemberInfo mi, bool declared)
            var propertyTypeIsSet = mi.GetPropertyOrFieldType()
            if (propertyTypeIsSet) return true;
            var backFieldInfo = PropertyToField.GetBackFieldInfo((PropertyInfo)mi);
            return backFieldInfo != null
                   && backFieldInfo
Remember to add the collection type factory to your config..

© NHibernate Community 2024