流利的NHibernate的问题 [英] Fluent NHibernate question
问题描述
$ b
UserRoles - UserID(int),Role(string)
我想要的是我的User类在我的域中拥有一个IList角色。如何构建我的流利的NHibernate映射来实现这一目标?
您正在寻找的是一组元素,在标准的hbm映射中:
< set name =Rolestable =UserRoles>
< key column =UserID/>
< element column =Role/>
< / set>
对于流畅的NHibernate,您可以这样映射:
HasMany< string>(x => x.Roles)
.AsElement(Role);
您可能还需要使用 WithKeyColumn(string)
。
Let's say you have two tables, "Users" and "UserRoles". Here's how the two tables are structured (table - columns):
Users - UserID (int)
UserRoles - UserID (int), Role (string)
What I want is for my "User" class in my domain to have an IList of roles. How do I construct my Fluent NHibernate mapping to achieve this?
What you're looking for is a of a set of elements, which in standard hbm mapping is:
<set name="Roles" table="UserRoles">
<key column="UserID" />
<element column="Role" />
</set>
For Fluent NHibernate you can map this like so:
HasMany<string>(x => x.Roles)
.AsElement("Role");
You may need to also specify the key name using WithKeyColumn(string)
.
这篇关于流利的NHibernate的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!