Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent NHibernate - bind List<int>

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 Answers

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

The mapping should look something like:

HasMany(x=> x.userRights).Element("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.

like image 56
Min Avatar answered Dec 04 '25 22:12

Min