流利的NHibernate - 绑定List< int> [英] Fluent NHibernate - bind List<int>
问题描述
public class User {
public virtual int ID;
公共虚拟字符串名称;
公共虚拟IList< int> userRights;
}
我想创建一个UserMap:ClassMap< User>
映射名称没有问题,但是我似乎无法弄清楚如何映射userRights。表> b
$ b
UserTable
User_id int
User_Name nvarchar
User_group int
UserRights
User_group int
RightID int
你如何映射这个?解析方案
那么如果你想要一个List,你需要一个索引。所以我会建议只是把它作为一个ICollection,除非订购是显着的。
映射应该看起来像这样:
HasMany(x => x.userRights).Element(RightID)。AsBag();
然而,看着你的桌子,我注意到一些奇怪的东西。您正试图在User_Rights表中使用主键而不使用主键。如果你在UserRights中有User_Id,那么上面的代码就可以工作了。
否则,它看起来像是一个UserGroup,应该由你的类来建模。
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 ?
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.
这篇关于流利的NHibernate - 绑定List< int>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!