Question

My NHibernate mappings include a <database-object> element to define indexes for MS SQL Server 2008. The problem is that this SQL doesn't get included in the schema when I call SchemaExport.Create. Everything else gets created, but there are no indexes.

One of the entities looks like this, for example:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

  <class xmlns="urn:nhibernate-mapping-2.2" 
      name="MyApp.Entities.SomeEntity, MyApp.Entities" table="SomeEntity">

    <!- -->

  </class>

  <database-object>
    <create>
      CREATE INDEX [Idx_SomeEntityIndex] ON [SomeEntity] 
          ([Field1] ASC, [Field2] ASC) INCLUDE ( [Field3], [Field4], [Field5])
      CREATE STATISTICS [Stat_SomeEntityStat] ON [SomeEntity] 
          ([Field1], [Field2])
    </create>
    <drop>
      DROP INDEX [Idx_SomeEntityIndex] ON [SomeEntity]
      DROP STATISTICS [Stat_SomeEntityStat]
    </drop>
    <dialect-scope name="NHibernate.Dialect.MsSql2008Dialect, NHibernate"/>
  </database-object>

</hibernate-mapping>

The problem is that this used to work before (probably before moving from NH2 to NH3), and I am not sure if something changed in NHibernate which prevents this from executing.

Dialect matches my dialect in the config file.

Was it helpful?

Solution

Thanks to @OskarBerggren, I got the answer at a different forum. The problem was that the assembly name (NHibernate, in this case) should not have been specified inside the dialect string.

So, when I changed this:

<dialect-scope name="NHibernate.Dialect.MsSql2008Dialect, NHibernate"/>

to this:

<dialect-scope name="NHibernate.Dialect.MsSql2008Dialect"/>

it fixed my issues.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top