A list is an indexed, ordered, collection of entities. A bag is an unindexed, in ordered collection. I'm guessing that because your entity doesn't have a primary key, there was no way for NHibernate to index or order it.
On Fri, Mar 27, 2009 at 11:03 AM, Paul Batum <[email protected]> wrote: > That would be a question best posed to the main NH list as it is really a > question about the behavior of NHibernate's different collection types. > > > On Fri, Mar 27, 2009 at 10:24 AM, Jeremy Wadsack <[email protected] > > wrote: > >> >> So I've found (along the lines of the previous post) that changing to >> AsBag instead of AsList fixes this error (and introduces others that >> I'll dig into). I don't really understand why. >> >> Can anyone shed light on that? >> >> - Jeremy >> >> >> On Mar 26, 3:33 pm, Jeremy Wadsack <[email protected]> wrote: >> > I have a class of users with permissions that are set from an enum. >> > The database doesn't have a primary key in the permissions table, so I >> > built a composite key. This all seems to work until I try to load/ >> > write to the permissions table. Fluent NHibernate (or maybe just >> > NHibernate) wants to insert a rogue column IDX. >> > >> > See similar post: >> http://groups.google.com/group/fluent-nhibernate/browse_thread/thread... >> > >> > I've pulled the latest source and still am having no luck. I've tried >> > lots of suggestions from the couple instances I found like this >> > (change AsList to AsSet, settings column names, ...). All the jiggery >> > in the AdminMap class is just trying to get this working. No luck. >> > >> > Any idea why this is happening or how to fix it? >> > >> > TIA, >> > >> > Jeremy Wadsack >> > >> > --------------------------------------------------- >> > Source: >> > --------------------------------------------------- >> > public class Admin >> > { >> > public virtual int Id { get; private set; } >> > public virtual string Name { get; set; } >> > public virtual string Password { get; set; } >> > public virtual string Email { get; set; } >> > public virtual IList<AdminAccess> AdminAccesses { get; private >> > set; } >> > >> > public Admin() { >> > AdminAccesses = new List<AdminAccess>(); >> > } >> > } >> > >> > public class AdminAccess >> > { >> > public virtual Admin Admin { get; set; } >> > public virtual Function Function { get; set; } >> > public virtual int GroupId { get; set; } >> > // -- removed Equals implementations neede bu NHibernate for >> > composite keys >> > } >> > >> > public class AdminMap : ClassMap<Admin> >> > { >> > public AdminMap() { >> > WithTable("t_admin"); >> > >> > Id(x => x.Id, "admin_id"); >> > >> > Map(x => x.Name, "name"); >> > Map(x => x.Email, "email"); >> > Map(x => x.Password, "password"); >> > >> > HasMany( x => x.AdminAccesses ) >> > .AsList() >> > .KeyColumnNames.Clear() >> > .KeyColumnNames.Add( "admin_id" ) >> > .Cascade.All() >> > .Not.LazyLoad(); >> > } >> > } >> > >> > public class AdminAccessMap : ClassMap<AdminAccess> >> > { >> > public AdminAccessMap() { >> > WithTable("t_admin_access"); >> > >> > UseCompositeId() >> > .WithKeyProperty( x => x.Function, "function_id" ) >> > .WithKeyProperty( x => x.GroupId, "group_id" ) >> > .WithKeyReference( x => x.Admin, "admin_id" ); >> > >> > References( x => x.Admin, "admin_id" ); >> > >> > Map(x => x.GroupId, "group_id"); >> > Map(x => x.Function, "function_id"); >> > >> > } >> > } >> > >> > ------------------------------------------------------ >> > And here's the DDL that it spits out: >> > ------------------------------------------------------ >> > >> > create table t_admin ( >> > admin_id INT IDENTITY NOT NULL, >> > email NVARCHAR(255) null, >> > password NVARCHAR(255) null, >> > name NVARCHAR(255) null, >> > primary key (admin_id) >> > ) >> > create table t_admin_access ( >> > function_id INT not null, >> > group_id INT not null, >> > admin_id INT not null, >> > idx INT null, >> > primary key (function_id, group_id, admin_id) >> > ) >> >> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---
