PersistentBag exception in Orchard

Go To StackoverFlow.com

1

I'm trying to adapt the guide http://docs.orchardproject.net/Documentation/Creating-1-n-and-n-n-relations for creating an N-to-N relation in my Orchard module, but I get an exception "unable to cast NHibernate.Collection.Generic.PersistentGenericBag`1[ArealAds.Models.StreetAreaRecord] to System.Collections.Generic.List`1[ArealAds.Models.StreetAreaRecord]". I don't fully understand what's going on behind the scenes so it's hard for me to debug. What is the likely cause of this error? Where do I start looking?

2012-04-04 05:15
by Alexei Averchenko


1

You should change the type of the related item collection from List<T> to IList<T> (or more generic IEnumerable<T>), as NHibernate cannot map the property to it's internal item collection (which implements IList<T>).

See similar issue.

2012-04-05 11:45
by Piotr Szmyd
Already did, nothing changed : - Alexei Averchenko 2012-04-05 15:14
Check if you changed that in all necessary places. Also, please paste the whole code for your record classes so we could get a better insight. I'm using a signature like this: public virtual IList<MyRecord> RelatedRecords { get; set; } and it works without problems - Piotr Szmyd 2012-04-05 16:54
Looks like that was it after all - Alexei Averchenko 2012-04-09 11:54


1

You did not correctly follow the guide. There is an example of an n-n relationship in the document and it works. Without seeing any of your code, it's hard to say what went wrong, but it has to be different from the tutorial somehow. Another example you can look at is the bundle part in this module: https://bitbucket.org/bleroy/nwazet.commerce. it establishes a n-n relationship between content items.

2012-04-04 08:55
by Bertrand Le Roy
Ads