You could perhaps use a factory based off of that enum that was defined in
your Permission class. That way you could still pass the enum around, and
then just call the factory method when you wanted to get the corresponding
Permission object. You could even create an extension method off of the enum
that could do that if you wanted.

On Mon, Jun 15, 2009 at 3:21 PM, Loki <[email protected]> wrote:

>
> I did create one to mimic the way I used to do an enumeration like
> this.   It's a simple int id and varchar name table.  I'm not opposed
> to using one, but I would like to have the enum in my code and not
> have to manage the data in the enum and in the database.
>
> The permissions will be changing as I add new features that require
> certain permissions.  And there will be a lot in the end.
>
> On Jun 15, 11:10 am, Ben Hyrman <[email protected]> wrote:
> > If I understand
> >
> > You have class User
> > You have table User
> > You have table UserPermission
> >
> > Do you have table Permission?
> >
> > Is Permission a fairly static set?
> >
> >
> >
> > On Sun, Jun 14, 2009 at 5:16 PM, Loki<[email protected]>
> wrote:
> >
> > > I've been trying for some time with no luck on this issue, so I home
> > > someone here has done what I am trying to do.
> >
> > > I have an enum - in my case it is particular permissions for tasks a
> > > person can do - add content, delete content, edit users, delete users,
> > > etc.  This is an Enum in my project called Permissions.  I want to use
> > > an enum rather than a class object so I can do something like bool
> > > UserHasPermission(Permission.DeleteUser);
> >
> > > Permissions can either be given to a role to allow me to custom build
> > > roles as I need with varied sets of tasks that role can perform, or
> > > given to an individual user.  More than one permission can be granted
> > > to a role or user.
> >
> > > In my database, I have the user table and then a UserPermissions table
> > > which maps the user's id to any number of permissions.  Now, I will
> > > accept mapping the string value of the enum or the int value.  I just
> > > want it to work.  I do not want to have to manage 2 sets of
> > > permissions (one in code and one in the database), unless I have to.
> > > If nhibernate could take my enum class and autopopulate a table with
> > > my enum int value for the PK and the name, picking up on changes,
> > > etc., that would be nice.
> >
> > > Right now, I have a mapping where x.Permissions is an IList of type
> > > Permission (my enum).
> >
> > > HasManyToMany(x => x.Permissions)
> > >                 .WithParentKeyColumn("UserId")
> > >                 .WithChildKeyColumn("PermissionId")
> > >                 .WithTableName("UserPermissions")
> > >                 .LazyLoad();
> >
> > > This mapping errors saying that the type Permission is unmapped.
> >
> > > If anyone can point me in the right direction on mapping a list of
> > > enums to an object, it would be much appreciated.- Hide quoted text -
> >
> > - Show quoted text -
> >
>


-- 
- Hudson
http://www.bestguesstheory.com
http://twitter.com/HudsonAkridge

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to