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?
Asked
Active
Viewed 149 times
2 Answers
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.

Bertrand Le Roy
- 17,731
- 2
- 27
- 33
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.

Community
- 1
- 1

Piotr Szmyd
- 13,371
- 6
- 44
- 61
-
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
RelatedRecords { get; set; }` and it works without problems. – Piotr Szmyd Apr 05 '12 at 16:54 -
Looks like that was it after all. – Alexei Averchenko Apr 09 '12 at 11:54