0

How can I fluently map 2 entities that are joined together using a "join" table (it has 2 primary keys).

My entities:

Users
Roles

Then the 'join' table looks like:

RolesUsers
  RoleId
  UserId

So I want to query like this:

user.Roles

1 Answer 1

1

In Fluent NHibernate this is achieved by using HasManyToMany in your mapping. Ex: (User mapping)

 HasManyToMany(x => x.Roles)
                .Table("RolesUsers")
                .ParentKeyColumn("UserId")
                .ChildKeyColumn("RoleId")
                .Cascade.All()
                .Inverse()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.