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?
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.
public virtual IList<MyRecord> RelatedRecords { get; set; }
and it works without problems - Piotr Szmyd 2012-04-05 16:54
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.