views:

431

answers:

2

Hi

I have a Class which looks something like this:

 public class User {
      public virtual int ID;
      public virtual string Name;
      public virtual IList<int> userRights;
 }

 I want to make a UserMap : ClassMap<User>

Mapping the name is no problem however i cant seem to figure out how to map the userRights.

Table looks like

UserTable
User_id int
User_Name nvarchar
User_group int

UserRights
User_group int
RightID int

How would you map this ?

+1  A: 

Well if you want a List you need an index. So I would recommend just making it an ICollection unless the ordering is significant.

It should look something like:

HasMany(x=> x.userRights).AsElement("RightID").AsBag();

However, upon looking at your tables, I noticed something odd. You're trying to use a one-to-many without having the primary key in the User_Rights table. If you had User_Id in UserRights the above should work.

Otherwise it looks like there's a UserGroup, which should be modeled by your classes.

Min
A: 

Is there no way to Model around that ?

It is true that my User is refering to a Group which in turn has Rights, however i would like the mapping to indicate simply that my User has Rights.

Morten Schmidt

related questions