Fluent NHibernate - bind List<int>

余生颓废 提交于 2019-12-12 09:51:28

问题


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:


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.



来源:https://stackoverflow.com/questions/877924/fluent-nhibernate-bind-listint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!