我的NHibernate映射包含一个<database-object>元素,用于定义MS SQL Server2008的索引。问题是当我调用SchemaExport.Create时,这个SQL没有包含在模式中。其他所有内容都会被创建,但没有索引。
其中一个实体如下所示,例如:
<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>问题是,这在以前是有效的(可能在从NH2转移到NH3之前),我不确定NHibernate中是否有什么变化阻止了它的执行。
方言与我在配置文件中的方言相匹配。
发布于 2012-10-30 17:46:45
感谢@OskarBerggren,我在一个不同的论坛上得到了答案。问题是不应该在方言字符串中指定程序集名称(在本例中为NHibernate)。
所以,当我改变这个的时候:
<dialect-scope name="NHibernate.Dialect.MsSql2008Dialect, NHibernate"/>要这样做:
<dialect-scope name="NHibernate.Dialect.MsSql2008Dialect"/>它解决了我的问题。
https://stackoverflow.com/questions/13028567
复制相似问题