开发者

Mapping using an intermediate join table with 2 primary keys

开发者 https://www.devze.com 2023-04-13 08:21 出处:网络
How can I fluently map 2 entities that are joined together using a \"join\" table (it has 2 primary keys).

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 wan开发者_运维百科t to query like this:

user.Roles


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()
0

精彩评论

暂无评论...
验证码 换一张
取 消