Thanks, it works! On Feb 27, 1:07 pm, Robert Eberhart <robert.eberh...@gmail.com> wrote: > I asked a similar question, actually a message or two before you, and > had a difficult time trying to arrive at an answer. I tried a number > of different solutions and nothing worked. > > My answer, if I applied the same solution in your case, would be to > remove the composite key on UserRoleSetting and add an identity > primary key. You will need to make UserRoleSetting an entity in its > own right. Once you have the identity, you can then map it. > UserRoleSetting could be associated with whatever entity you would > like based on particular key column in a list. > > public class UserMap : ClassMap<User> { > public UserMap() { > Table("User"); > Id(x => x.Id, "UserId"); > ..... > HasMany<UserRoleSetting>(x => x.UserRoleSettings) > .Table("UserRoleSetting") > .KeyColumn("UserId") > .AsBag(); > } > > } > > You could probably do the same with Role and Module but access > UserRoleSetting on a different KeyColumn. > > public class UserRoleSettingMap : ClassMap<UserRoleSetting> { > public UserRoleSettingMap() { > Table("UserRoleSetting"); > Id(x => x.Id, "UserRoleSettingId"); > References<User>(x => x.User, "UserId"); > References<Role>(x => x.Role, "RoleId"); > References<Module>(x => x.Module, "ModuleId"); > } > > } > > Other people may have a better answer, but, so far, I haven't heard it. > > 2011/2/26 Hardy <hardy.yin.w...@gmail.com>: > > > > > Hi all, > > > CREATE TABLE [dbo].[User]( > > [UserID] [int] IDENTITY(1,1) NOT NULL, > > [UserName] [varchar](50) NOT NULL, > > [Password] [varchar](50) NOT NULL, > > CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED ( > > [UserID] ASC ) ON [PRIMARY] > > > CREATE TABLE [dbo].[Module]( > > [ModuleID] [int] NOT NULL, > > [ModuleName] [nvarchar](50) NOT NULL, > > CONSTRAINT [PK_Module] PRIMARY KEY CLUSTERED ( > > [ModuleID] ASC ) ON [PRIMARY] > > > CREATE TABLE [dbo].[Role]( > > [RoleID] [int] NOT NULL, > > [RoleName] [nvarchar](50) NOT NULL, > > CONSTRAINT [PK_Role] PRIMARY KEY CLUSTERED ( > > [RoleID] ASC ) ON [PRIMARY] > > > CREATE TABLE [dbo].[UserRoleSetting]( > > [UserID] [int] NOT NULL, /* FK to User table */ > > [ModuleID] [int] NOT NULL, /* FK to Module table */ > > [RoleID] [int] NOT NULL, /* FK to Role table */ > > CONSTRAINT [PK_UserRoleSetting] PRIMARY KEY CLUSTERED ( > > [UserID] ASC, > > [ModuleID] ASC ) ON [PRIMARY] > > GO > > > I have a schema like this to define the users have different roles > > under different modules. I know if UserRoleSetting table is just a > > simple many to many relationship table, it is easy to define. But that > > table actually contains relationship from 3 different tables, so what > > might be the correct syntax to load user role settings into user > > object? > > > Thanks > > > Hardy > > > -- > > 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 > > athttp://groups.google.com/group/fluent-nhibernate?hl=en.- Hide quoted text > > - > > - Show quoted text -
-- 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.