Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8885483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:19:17+00:00 2026-06-14T21:19:17+00:00

I need to create a non-clustered index with INCLUDE columns (see the <create> tag

  • 0

I need to create a non-clustered index with INCLUDE columns (see the <create> tag below). Here’s the mapping file:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="MyApp" assembly="MyApp">
  <class name="User" table="user" >
    <id name="Id" type="Guid" column="user_id">
      <generator class="guid.comb"/>
    </id>

    <property name="Name" column="name" not-null="true"  />
    <property name="Phone" column="phone" />
    <property name="Zipcode" column="zipcode" />
  </class>

  <database-object>
    <create>
      CREATE NONCLUSTERED INDEX [IX_user_zipcode_id]
      ON User (Zipcode)
      INCLUDE (Name, Phone)
    </create>
    <drop>
      DROP INDEX IX_user_zipcode_id
    </drop>
    <dialect-scope name="NHibernate.Dialect.MsSql2000Dialect"/>
    <dialect-scope name="NHibernate.Dialect.MsSql2005Dialect"/>
    <dialect-scope name="NHibernate.Dialect.MsSql2008Dialect"/>

  </database-object>

</hibernate-mapping>

The problem I’m having is the index is not created at all. Nothing appears to be happening. This is my first time using <database-object> so I may be doing something wrong here.

I’m guessing INCLUDE is Sql Server specific which is why the dialect-scope is there. I know how to create a single and multi-column index, but this is not what I want. I want a single column index on zipcode and all other columns in the User table part of the INCLUDE clause of the query. Is there any way to create this type of index using the mapping file or some other way?

This is probably a long shot, but it would be nice to not have to specify every column but the indexed one in the INCLUDE part of the query… Instead to just let nhibernate add any new columns to the index that are added as properties to the mapping file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:19:18+00:00Added an answer on June 14, 2026 at 9:19 pm

    So part of the problem was indeed my lack of understanding the database-object tag due mostly to poor documentation. From what I’ve gathered, the <create> and <drop> tags are only used when using SchemaExport like so:

        Dim schemaExport As SchemaExport = New SchemaExport(NhibernateConfiguration)
        schemaExport.Execute(False, True, False)
    

    My app doesn’t create the schema using that class. Instead it uses SchemaUpdate so the schema isn’t blown away every time (the database may already exist on the users machine):

        Dim schemaUpdate As SchemaUpdate = New SchemaUpdate(NhibernateConfiguration)
        schemaUpdate.Execute(False, True)
    

    That was the problem. The next logical question to ask is then how do you execute sql using SchemaUpdate. The answer… you can’t. See this post: https://forum.hibernate.org/viewtopic.php?f=6&t=969584&view=next

    Alas I am left to use raw sql. Maybe some day they will add an <update> tag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Non-database programmer here. It happens so, that I need to create a function in
I heard that you need to create images for both retina and non-retina. And
I'd like to create an index on a view I have but I need
I need to create a non sequential list of numbers that fit within a
I need to create a Python string consisting of non-ascii bytes to be used
As a part of my project I need to create non repeating 2 or
I need to create a non modal Silverlight 4.0 control that would appear (pop
I need to create some forms non-linked to entities. I pretty understood how create
I need to create a basic column chart using highcharts. Here's my PHP code:
I need to create a custom attribute that is applicable only for non static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.