I have a table User, fields : Id, Username
I have a table UserGroup, fields : Id, UsergroupName, Code
I'd like assign several Usergroup by user, that's mean, I have to have a third table with : UserId and UsergroupId, these table is named UsersGroups
I tried this code :
User table, XML :
<bag name="UsersGroups" generic="true" cascade="all" inverse="false" table="UsersGroups" >
<key column="UserId" />
<many-to-many column="GroupId" class="LookupUserGroup" />
</bag>
User table, C# :
public virtual IList<UserGroup> UsersGroups { get; set; }
Group table, C# (nothing in XML mapping):
public virtual User User { get; set; }
To add a group to a User, I use AddGroup in the User class, I do this :
public virtual void AddGroup(UserGroup userGroup)
{
userGroup.User = this;
UsersGroups.Add(userGroup);
}
When I make a query on User, I'd like use linq to make some check on the "Code" field like this :
var res = (from c in MyUserList where c.UserGroup.Code == 1 select c);
but USergroup field are not available in the intellisense.
Any idea ?
Thanks,