Problem with "Creating-1-n-and-n-n-relations" example

Topics: Writing modules
May 30, 2012 at 8:28 AM

Hi guys,

I need help about the tutorial  "Creating-1-n-and-n-n-relations".

I did a part SkillsPart and a part TeamMemberPart, one TeamMemberPartRecord can have more than one relationship with Skills.

When I try to save the data I receive an error.

I look at the log file and I got the following error:

2012-05-30 10:08:14,400 [39] Orchard.ContentManagement.DefaultContentManager - InvalidCastException thrown from IContentHandler by Orchard.Raise.Common.Handlers.TeamMemberHandlerSystem.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List`1[Orchard.Raise.Common.Models.ContentTeamMemberSkillsRecord]' to type 'System.Collections.Generic.IList`1[Orchard.Raise.Common.Models.SkillPartRecord]'.   at NHibernate.Type.GenericBagType`1.Wrap(ISessionImplementor session, Object collection)   at NHibernate.Event.Default.WrapVisitor.ProcessArrayOrNewCollection(Object collection, CollectionType collectionType)   at NHibernate.Event.Default.WrapVisitor.ProcessCollection(Object collection, CollectionType collectionType)   at NHibernate.Event.Default.AbstractVisitor.ProcessValue(Object value, IType type)   at NHibernate.Event.Default.WrapVisitor.ProcessValue(Int32 i, Object[] values, IType[] types)   at NHibernate.Event.Default.AbstractVisitor.ProcessEntityPropertyValues(Object[] values, IType[] types)   at NHibernate.Event.Default.AbstractSaveEventListener.VisitCollectionsBeforeSave(Object entity, Object id, Object[] values, IType[] types, IEventSource source)   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)   at NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)   at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)   at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)   at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)   at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)   at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)   at NHibernate.Impl.SessionImpl.Save(Object obj)   at Orchard.Data.Repository`1.Create(T entity) in D:\work\Raise\Raise.Web\src\Orchard\Data\Repository.cs:line 96   at Orchard.Data.Repository`1.Orchard.Data.IRepository<T>.Create(T entity) in D:\work\Raise\Raise.Web\src\Orchard\Data\Repository.cs:line 36   at Orchard.ContentManagement.Handlers.StorageFilter`1.CreateRecordCore(ContentItemVersionRecord versionRecord, TRecord record) in D:\work\Raise\Raise.Web\src\Orchard\ContentManagement\Handlers\StorageFilter.cs:line 35   at Orchard.ContentManagement.Handlers.StorageFilter`1.Creating(CreateContentContext context, ContentPart`1 instance) in D:\work\Raise\Raise.Web\src\Orchard\ContentManagement\Handlers\StorageFilter.cs:line 49   at Orchard.ContentManagement.Handlers.StorageFilterBase`1.Orchard.ContentManagement.Handlers.IContentStorageFilter.Creating(CreateContentContext context) in D:\work\Raise\Raise.Web\src\Orchard\ContentManagement\Handlers\StorageFilterBase.cs:line 36   at Orchard.ContentManagement.Handlers.ContentHandler.Orchard.ContentManagement.Handlers.IContentHandler.Creating(CreateContentContext context) in D:\work\Raise\Raise.Web\src\Orchard\ContentManagement\Handlers\ContentHandler.cs:line 220   at Orchard.ContentManagement.DefaultContentManager.<>c__DisplayClass58.<Create>b__54(IContentHandler handler) in D:\work\Raise\Raise.Web\src\Orchard\ContentManagement\DefaultContentManager.cs:line 476   at Orchard.InvokeExtensions.Invoke[TEvents](IEnumerable`1 events, Action`1 dispatch, ILogger logger) in D:\work\Raise\Raise.Web\src\Orchard\InvokeExtensions.cs:line 192012-05-30 10:08:33,893 [39] NHibernate.Impl.AbstractSessionImpl - DTC transaction prepre phase failedSystem.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List`1[Orchard.Raise.Common.Models.ContentTeamMemberSkillsRecord]' to type 'System.Collections.Generic.IList`1[Orchard.Raise.Common.Models.SkillPartRecord]'.   at NHibernate.Type.GenericBagType`1.Wrap(ISessionImplementor session, Object collection)   at NHibernate.Event.Default.WrapVisitor.ProcessArrayOrNewCollection(Object collection, CollectionType collectionType)   at NHibernate.Event.Default.WrapVisitor.ProcessCollection(Object collection, CollectionType collectionType)   at NHibernate.Event.Default.AbstractVisitor.ProcessValue(Object value, IType type)   at NHibernate.Event.Default.WrapVisitor.ProcessValue(Int32 i, Object[] values, IType[] types)   at NHibernate.Event.Default.AbstractVisitor.ProcessEntityPropertyValues(Object[] values, IType[] types)   at NHibernate.Event.Default.DefaultFlushEntityEventListener.WrapCollections(IEventSource session, IEntityPersister persister, IType[] types, Object[] values)   at NHibernate.Event.Default.DefaultFlushEntityEventListener.OnFlushEntity(FlushEntityEvent event)   at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEntities(FlushEvent event)   at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event)   at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)   at NHibernate.Impl.SessionImpl.Flush()   at NHibernate.Transaction.AdoNetWithDistrubtedTransactionFactory.DistributedTransactionContext.System.Transactions.IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)

 

Anybody can help me?

May 30, 2012 at 10:27 AM

in the following link you can find the source code: http://www.4shared.com/rar/0cTFROb1/OrchardRaiseCommon.html

May 30, 2012 at 10:45 AM

I cannot download that file it seems without having a user acc there, but I think I know a solution.

In your record class, replace every occurance of List< with IList<

May 30, 2012 at 4:16 PM

Ok I will try in few minutes...

anyway this is the link to the source code: http://sdrv.ms/JPgotL

May 30, 2012 at 4:29 PM

Thank you very much, it's the solution of my trouble...

NHibernate grrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr :)