Since SQL Azure requires clustered indexes for every table for replication (see here http://blogs.msdn.com/b/sqlazure/archive/2010/05/12/10011257.aspx) I have added the following MsSqlAzureDialect to my MsSqlConfiguration:
public class MsSqlAzureDialect : MsSql2008Dialect
{
public override string PrimaryKeyString
{
get { return "primary key CLUSTERED"; }
}
}
However, that doesn't solve the problem I'm currently having with a Many-to-Many table. I currently have a situation where I have a User with Roles a Role with Users. So there is a Many-to-Many relationship between Users and Roles and a link table generated by NHibernate. So in my UserAutomappingOverride I have something like this:
public class UserAutomappingOverride : IAutoMappingOverride<User>
{
public void Override(AutoMapping<User> mapping)
{
mapping.HasManyToMany(x => x.Roles).Cascade.SaveUpdate();
}
}
This results in NHibernate creating a linking table called RoleToUser. However, this table doesn't have a PK and therefore no Clustered Index. Which is an invalid table configuration for use in SQL Azure.
I've tried to use Database Objects from non-fluent NHibernate like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<nhibernate-mapping>
<database-object>
<create>create clustered index ix on RoleToUser(User_id, Role_id)</create>
<drop>drop index RoleToUser.ix</drop>
</database-object>
</nhibernate-mapping>
But that was a shot in the dark to try and combine that non-fluent NHibernate code in a fluent configuration. It didn't work however, because of an error that said "For security reasons DTD is prohibited in this XML document..."
Note: I'm using fluent NHibernate for code first database creation. So I am actually using my entities and AutomappingOverrides to generate the schema of the database on deployment.
Any help would be much appreciated.