流利的NHibernate:如何在多对多连接表上创建聚集索引? [英] Fluent NHibernate: How to create a clustered index on a Many-to-Many Join Table?

查看:173
本文介绍了流利的NHibernate:如何在多对多连接表上创建聚集索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在SQL Azure上使用我的Fluent NHibernate映射,我需要在每个表上都有一个聚集索引。 Fluent NHibernate为多对多连接创建的默认堆表显然不会这样做,因为它们没有主键。



我希望能够告诉关系的一方为它的连接表创建一个聚集索引,但我不知道如何。这里是我的映射看起来像:

$ p $ public class UserMap:ClassMap< User> {
public UserMap()
{
表(用户);
Id(x => x.UserId).GeneratedBy.Identity()。Column(UserId);
Map(x => x.UserName).Unique()。Not.Nullable()。Length(DataConstants.UserNameLength).Column(UserName);
Map(x => x.Email).Unique()。Not.Nullable()。Length(DataConstants.EmailAddressLength).Column(Email);
Map(x => x.Password).Not.Nullable()。Length(DataConstants.PasswordHashLength).Column(Password);
HasMany(x => x.Clicks).Cascade.AllDeleteOrphan();
HasManyToMany(x => x.Roles).Cascade.SaveUpdate()。Table(UsersInRole)。ParentKeyColumn(UserId)。
ChildKeyColumn(RoleId);





如果你需要,请告诉我更多信息!

解决方案

我不知道Fluent是否直接支持它(如果没有,只需包含xml)您可以使用辅助数据库对象

 < nhibernate-mapping> 
< database-object>
< create>在UsersInRole(UserId,RoleId)上创建聚集索引ix< / create>
< drop> drop index UsersInRole.ix< / drop>
< / database-object>
< / nhibernate-mapping>


In order to use my Fluent NHibernate mappings on SQL Azure, I need to have a clustered index on every table. The default heap tables that Fluent NHibernate creates for many-to-many joins obviously don't do this as they don't have primary keys.

I want to be able to tell one side of the relationship to create a clustered index for its join table, but I'm not sure how. Here's what my mappings look like:

 public class UserMap : ClassMap<User>{
    public UserMap()
    {
        Table("Users");
        Id(x => x.UserId).GeneratedBy.Identity().Column("UserId");
        Map(x => x.UserName).Unique().Not.Nullable().Length(DataConstants.UserNameLength).Column("UserName");
        Map(x => x.Email).Unique().Not.Nullable().Length(DataConstants.EmailAddressLength).Column("Email");
        Map(x => x.Password).Not.Nullable().Length(DataConstants.PasswordHashLength).Column("Password");
        HasMany(x => x.Clicks).Cascade.AllDeleteOrphan();
        HasManyToMany(x => x.Roles).Cascade.SaveUpdate().Table("UsersInRole").ParentKeyColumn("UserId").
            ChildKeyColumn("RoleId");

    }
}

Please let me know if you need any more information!

解决方案

I don't know if Fluent supports it directly (if not, just include the xml), but you can do it with Auxiliary Database Objects

<nhibernate-mapping>
  <database-object>
    <create>create clustered index ix on UsersInRole(UserId, RoleId)</create>
    <drop>drop index UsersInRole.ix</drop>
  </database-object>
</nhibernate-mapping>

这篇关于流利的NHibernate:如何在多对多连接表上创建聚集索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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