Search code examples
c#nhibernatesmartclient

The type or namespace name 'PersistentBag' does not exist in the namespace 'NHibernate.Collection'


I'm upgrading a Windows SmartClient solution from nHibernate 2.2 to 4.0, using NuGet in Visual Studio 2013.

On this line:

sb.Append ("=" + ((NHibernate.Collection.PersistentBag) state[i]).Count.ToString() + " items");

I get this error:

The type or namespace name 'PersistentBag' does not exist in the namespace 'NHibernate.Collection'

Suggested choices by Visual Studio (when typing the .) are:

  • AbstractPersistentCollection
  • Generic ( a namespace)
  • IPersistentCollection (an interface)
  • PersistentArrayHolder

The second and third are not classes. The first and fourth does not have a Count() method.

Which one have to be used in this case?


Solution

  • There is no PersistentBag in NHibernate 4, only PersistentGenericBag<T>.

    It is an internal type of NH and not supposed to cast to.

    I don't know where this code is actually found. If it is your own, you could access Count by IList or ICollection, which are both implemented by the bag.

    If it is code from a framework you use, you probably have to use another NHibernate version.