My parent class: public class SomeData { public virtual Schedule schedule { get; set; } public virtual IEnumerable<SomeUser> SomeUsers{get;set} }
Child class: public class SomeUser : Entity { public virtual SomeData SomeData { get; set; } public virtual IUser AssignedTo { get; set; } } SomeData has One-To-Many relation with SomeUser. Mapping is as below: public class SomeDataMapping : NHibernateClassMapping<SomeData> { public SomeDataMapping() { References(x => x.Schedule).LazyLoad(); HasMany(x => x.SomeUser ).Inverse().Cascade.All() .KeyColumn("Schedule_Id").Table("SomeUsers"); } public class SomeUserMapping : ClassMap<SomeUser> { protected SomeUsersMapping() { Id(x => x.Id); References(x => x.SomeData).Column("Schedule_Id").Class<SomeData>().Not.Nullable(); References(x => x.AssignedTo).Column("AssignedTo_Id").Class<User>().Not.Nullable(); Table("SomeUsers"); } } } During the creation of the first Schedule which loads these data, it gets saved fine but if I try to edit and save. I get the below error: System.InvalidCastException: Unable to cast object of type 'WhereSelectListIterator`2[System.Int64,Project.Schedules.SomeUsers]' to type 'NHibernate.Collection.IPersistentCollection'. at NHibernate.Event.Default.FlushVisitor.ProcessCollection(Object collection, CollectionType type) at NHibernate.Event.Default.AbstractVisitor.ProcessEntityPropertyValues(Object[] values, IType[] types) at NHibernate.Event.Default.DefaultFlushEntityEventListener.OnFlushEntity(FlushEntityEvent event) at Project.ORM.Core.Configurations.CourseFlushEntityEventListener.OnFlushEntity(FlushEntityEvent e) in Below code is where I map view data to domain object schedule.SomeData.SomeUsers = viewDto.AssignedUserIds.Select(id => new SomeUser { SomeData = schedule.SomeData, AssignedTo = userRepo.FindBy(id) }); The return type here is IEnumerable. If I convert it to List() and try to save, i get the below error System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List`1[Project.Schedules.SomeUsers]' to type 'NHibernate.Collection.IPersistentCollection'. I have tried setting SomeUser as IEnumberable, ICollection, IList, tried updated the mapping using different option but not able to get over this. I recently implement another HasMany relation mapping the exact same way and it works fine. -- You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To unsubscribe from this group and stop receiving emails from it, send an email to fluent-nhibernate+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/fluent-nhibernate/31e9a10a-ae4c-423a-9870-7ec68b5d34d5n%40googlegroups.com.