0

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?

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139

2 Answers2

1

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.

Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
  • Using `IColleciton` does compile at least: `sb.Append (propertyName[i].ToLower() + "=" + ((System.Collections.ICollection)state[i]).Count.ToString() + " items");`. I'll test this when I get the other problems solved. – Al Lelopath Mar 24 '16 at 14:37
  • If you are updating NHibernate, you should take a look at the release notes of all the versions since the one you used to use before. There are most often some more surprises at runtime .... – Stefan Steinegger Mar 24 '16 at 14:56
0

I has code using this too. It looks like you can replace the persistentBag cast with an IList cast.

Daniel Williams
  • 8,912
  • 15
  • 68
  • 107