Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can define an index in NHibernate using &lt;database-object&gt; or IAuxiliaryDatabaseObject.</p> <p>In a hbm.xml file:</p> <pre><code>&lt;hibernate-mapping xmlns="urn:nhiernate-mapping-2.2"&gt; &lt;database-object&gt; &lt;create&gt;VALID SQL&lt;/create&gt; &lt;drop&gt;VALID SQL&lt;/create&gt; &lt;/database-object&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>N.B. &lt;database-object&gt; can go before or after a class mapping in the same hbm.xml file allowing you to keep your index definitions, triggers, etc. with the object to which they apply.</p> <p>The other option is NHibernate.Mapping.IAuxiliaryDatabaseObject:</p> <pre><code>namespace NHibernate.Mapping { public interface IAuxiliaryDatabaseObject : IRelationalModel { void AddDialectScope(string dialectName); bool AppliesToDialect(Dialect dialect); void SetParameterValues(IDictionary&lt;string, string&gt; parameters); } public interface IRelationalModel { string SqlCreateString(Dialect dialect, IMapping p, string defaultCatalog, string defaultSchema); string SqlDropString(Dialect dialect, string defaultCatalog, string defaultSchema); } } </code></pre> <p>Given that you're using Fluent NHibernate, IAuxiliaryDatabaseObject will probably work better for you. Just expose your configuration when building it and then call:</p> <pre><code>var sqlCreate = "CREATION SCRIPT"; var sqlDrop = "DROP SCRIPT"; cfg.AddAuxiliaryDatabaseObject(new SimpleAuxiliaryDatabaseObject(sqlCreate, sqlDrop)); </code></pre> <p>N.B. NHibernate.Mapping.SimpleAuxiliaryDatabaseObject is part of NHibernate. You don't have to write it yourself if all you need to do is supply create/drop scripts for a database object.</p> <p>I took a quick look in the Fluent NHibernate codebase and didn't see any direct support for IAuxiliaryDatabaseObject. So it is a matter of exposing your configuration object and supplying all your IAuxiliaryDatabaseObjects yourself. It wouldn't be too difficult to write some code that scan through your mapping assembly looking for types that implement IAuxiliaryDatabaseObject and then foreach'ing over them to pass to cfg.AddAuxiliaryDatabaseObject(obj).</p> <p>You can find more information about auxiliary database objects in the NHibernate docs:</p> <p><a href="http://nhibernate.info/doc/nh/en/index.html#mapping-database-object" rel="nofollow">http://nhibernate.info/doc/nh/en/index.html#mapping-database-object</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload