Hi!

I've got following domain model: Users -> Roles ( e.g. there are
multiple users and multiple roles. Each user can have multiple roles).

    public class User
    {
        public int ID { get; set; }
        public string UserName { get; set; }
        public string Email { get; set; }
        public string Password { get; set; }
        public bool IsActive { get; set; }
        public bool IsActivated { get; set; }
        public DateTime RegistrationDate { get; set; }
        public IList<Role> Roles { get; set; }

        public User()
        {
            Roles = new List<Role>();
        }

        public override string ToString()
        {
            return String.Format("{0},{1},{2},{3}", ID, UserName,
Password, IsActive);
        }
    }

    public class Role
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public IList<Permission> Permissions { get; set; }

        public Role()
        {
            Permissions = new List<Permission>();
        }

        public override string ToString()
        {
            return String.Format("ID={0},Name={1}", ID, Name);
        }
    }


I use standart many-to-many association using association table. It
works perfectly, but I need more fine grained control over
associations. There are some scenarios when I don't want to take
associations between User->Role into account and simply ignore them
(e.g. update only User (name, email etc)). Is it possible to ignore
cascade=all option in mapping file in some scenarios, and not to
ignore in others?

To illustrate the idea here are two scenarios:
1. Work with user entities (general scenario) - change e-mail,
password, userName etc. Server sends lightweight User entities to
client with Roles collection empty (since we're not working with
roles). Client updates User entities on UI and sends them back to
server. Since Permissions collection is empty (and I don't want to
transfer it from server to client and vise versa) NHibernate will
remove associations between users and roles due to cascade=all
2. Work with user permissions (e.g. admin scenario). Server sends full
User entities to client with Roles collection loaded. This way
cascade=all does it job perfectly.

So I need to tell NHbiernate somehow to ignore cascade=all in some
cases and use this option in others. Is there any possibility to
achieve this? Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en.

Reply via email to