Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your scenario is analogous to the linking of Store and Products in the example given in the <a href="http://wiki.fluentnhibernate.org/Getting_started" rel="nofollow noreferrer">Getting started with Fluent NHibernate</a>.</p> <p><em>UserRoles</em> is just a linking mechanism so you are better off not thinking of it as an entity. Instead, you have a <em>User</em> that has been assigned <em>Roles</em> and/or a <em>Role</em> that has been assigned to <em>Users</em>.</p> <p>So you might have:</p> <pre><code>public class User { public virtual int Id { get; private set; } public virtual string DisplayName { get; set; } public virtual string Email { get; set; } public virtual string Password { get; set; } public virtual IList&lt;Role&gt; Roles { get; set; } public User() { Roles = new List&lt;Role&gt;(); } public AddToRole(Role role) { role.Users.Add(this); Roles.Add(role); } } public class Role { public virtual int Id { get; private set; } public virtual string RoleName { get; set; } public virtual string RoleDescription { get; set; } public virtual IList&lt;User&gt; Users { get; set; } public Role() { Users = new List&lt;User&gt;(); } } public class UserMap : ClassMap&lt;User&gt; { public UserMap() { Id(x =&gt; x.Id); Map(x =&gt; x.DisplayName); Map(x =&gt; x.Email); Map(x =&gt; x.Password); HasManyToMany(x =&gt; x.Roles) .Table("UserRoles"); } } public class RoleMap : ClassMap&lt;Role&gt; { public RoleMap() { Id(x =&gt; x.Id); Map(x =&gt; x.RoleDescription); Map(x =&gt; x.RoleName); HasManyToMany(x =&gt; x.Users) .Inverse() .Table("UserRoles"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload