流利的NHibernate的问题 [英] Fluent NHibernate question

查看:108
本文介绍了流利的NHibernate的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,你有两个表,用户和UserRoles。下面是这两个表的结构(表 - 列):用户 - 用户ID(int)
$ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆