Paul, Thanks for taking a look at the problem and for providing the example.
I had just arrived at a solution for this issue in general. As you can see, the TItemListUserPerm table is table with a primary composite key. Setting up a table this way is not the way I would have modeled the data physically, but, it is what it is. To get this scenario to work, I had to remove the primary key, add an identity primary key, and then create an entity for the table itself. Once I did that, I was able to map the TaskItemList entity to the table based on the TItemListID key column. Even this was frustrating because I had issues with the fact that I had subclassed User and I was still referring to TaskItemListUser in some of the generic lists. Everything compiled, but when I tried to access the data I was getting some weird results. After I cleaned things up, "Presto Chango!" things started working great. I have learned quite a bit about data modeling through some of the work that I have been doing lately; what to do and what not to do. I think that is one of the cool things about working with an ORM; by using one, you really get a feel of how to model objects the "right" way (if there is such a thing), because if you don't, you will pay for it later. :-) Anyway, thanks again for your help. Sincerely, Robert Eberhart 2011/3/2 Paul Batum <paul.ba...@gmail.com>: > I'm just focusing on your error message without looking at your problem in > general. The "Illegal access to loading a collection" error is usually a > result of mistakenly mapping NH to a property getter or setter that has some > code in it. Something like this: > class Student > { > public School { > get { return _school; } > set > { > if(value != _school) > _school.Students.Remove(this); > _school = value; > } > } > Now generally this is a bad way to go, but I've seen code like this plenty > of times. In this scenario, it would be best to map NH to the field > directly, instead of the property. > Do your domain objects have any code like this? Any code in a property that > will run when NH uses that property to load an object can cause this issue. > > > On Fri, Feb 25, 2011 at 9:23 AM, TheNephalim <robert.eberh...@gmail.com> > wrote: >> >> I want to start with the fact that this is a legacy system. >> >> I have three tables: >> >> TItemList >> ------------------------ >> TItemListID (PK) >> >> SystemUser >> ------------------------ >> SystemUserID (PK) >> >> TItemListPerm >> ------------------------ >> TItemListPermID >> >> TItemListUserPerm >> ------------------------ >> TItemListID (PK,FK) >> UserID (PK, FK) >> TItemListPermID (PK,FK) >> >> Based on the database, I determined that we have a TaskItemList that >> contains TaskItems. At the list level, it has TaskItemListUsers that >> can have permissions to do things to the list. Based on this idea, I >> subclassed the User entity to create TaskItemListUser which had the >> additional property of Permissions (IList<TaskItemListPermission>). >> >> My mappings are as follows: >> >> public class TaskItemListMap : ClassMap<TaskItemList> { >> public TaskItemListMap() { >> Table("TItemList"); >> Id(x => x.Id, "TItemListId"); >> Map(x => x.Name, "TItemListName"); >> Map(x => x.Description, "TItemListDesc"); >> Map(x => x.CreateDate, "BeginTime"); >> Map(x => x.UpdateDate, "UpdateDate"); >> Map(x => x.UpdateUser, "UpdateUser"); >> HasMany<TaskItem>(x => x.TaskItems) >> .Table("TItem") >> .KeyColumn("TItemListID") >> .Cascade.All() >> .AsBag(); >> HasMany<TaskItemListUser>(x => x.Users) >> .KeyColumn("TItemListID") >> .Cascade.All() >> .AsBag(); >> } >> } >> >> public class TaskItemListUserMap : SubclassMap<TaskItemListUser> { >> public TaskItemListUserMap() { >> Table("(SELECT DISTINCT TItemListUserPerm.TItemListID, >> TItemListUserPerm.UserID FROM TItemListUserPerm)"); >> KeyColumn("UserId"); >> HasMany<TaskItemListPermission>(x => x.Permissions) >> .Table("TItemListUserPerm") >> .KeyColumn("TItemListPermID") >> .Cascade.All() >> .AsBag(); >> } >> } >> >> public class TaskItemListPermissionMap : >> ClassMap<TaskItemListPermission> { >> public TaskItemListPermissionMap() { >> Table("TItemListPerm"); >> Id(x => x.Id, "TItemListPermID"); >> Map(x => x.Name, "TItemListPermName"); >> } >> } >> >> The result of this mapping is that I can get the generic list of >> TaskItemLists without a problem. Each list has a list of distinct >> users, but I cannot get the permissions to map to each user properly. >> >> I am currently branching out into other possible solutions including >> making TaskItemUser a ValueObject (I'm using S#arp Architecture), and >> having the properties TaskItemList, User, and Permissions. The >> mapping that I have for this is currently: >> >> public class TaskItemListUserMap : SubclassMap<TaskItemListUser> { >> public TaskItemListUserMap() { >> Table("TItemListUserPerm"); >> CompositeId() >> .KeyProperty(x => x.TaskItemList, "TItemListID") >> .KeyProperty(x => x.User, "UserId"); >> } >> } >> >> However, using this as a solution gets me a list of TaskItemLists but >> an error of "Illegal access to loading collection" when I try to >> access the list of users. >> >> Any assistance would be appreciated. If necessary, I can post the >> code up to GitHub. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Fluent NHibernate" group. >> To post to this group, send email to fluent-nhibernate@googlegroups.com. >> To unsubscribe from this group, send email to >> fluent-nhibernate+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/fluent-nhibernate?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Fluent NHibernate" group. > To post to this group, send email to fluent-nhibernate@googlegroups.com. > To unsubscribe from this group, send email to > fluent-nhibernate+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/fluent-nhibernate?hl=en. > -- You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to fluent-nhibernate@googlegroups.com. To unsubscribe from this group, send email to fluent-nhibernate+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.