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

  • SEARCH
  • Home
  • 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 941625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:08:49+00:00 2026-05-15T22:08:49+00:00

i have an nhibernate solution and i’m trying to do a save, but i’m

  • 0

i have an nhibernate solution and i’m trying to do a save, but i’m getting this error:

Test method HelloMusic.Core.Test.CrudTests.TestTrackAdd threw exception: 
NHibernate.Exceptions.GenericADOException: could not insert collection: [HelloMusic.BLL.Track.Credits#20][SQL: INSERT INTO Tracks_Credits (TrackID, Index, CreditID) VALUES (@p0, @p1, @p2)] ---> System.Data.SqlClient.SqlException: Incorrect syntax near 'Index'. If this is intended as a part of a table hint, A WITH keyword and parenthesis are now required. See SQL Server Books Online for proper syntax.

The SQL is as follows:

NHibernate: SELECT this_.GenreID as GenreID9_0_, this_.GenreName as GenreName9_0_ FROM Genres this_
NHibernate: INSERT INTO Tracks (ContainsSamples, Description, HasExplicitLyrics, IsCover, Lyrics, Name, OrderIndex, GenreID) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7); select SCOPE_IDENTITY();@p0 = False, @p1 = 'Teh awesome18133437', @p2 = True, @p3 = False, @p4 = 'b'z in yer mouth18141375', @p5 = 'beez in yer mouth18141375', @p6 = 1, @p7 = 1
NHibernate: INSERT INTO Credits (Email, Location, Name, Role) VALUES (@p0, @p1, @p2, @p3); select SCOPE_IDENTITY();@p0 = 'foo@foo.com', @p1 = NULL, @p2 = 'Some Dood', @p3 = 'teh Awesums'
NHibernate: INSERT INTO Images (ForeignEntityID, ForeignEntityType, CreatedDate, Extension, FileName, Height, IsOriginal, LastModifiedDate, LocationPath, MetaData, SizeInKiloBytes, Type, Width) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12); select SCOPE_IDENTITY();@p0 = 0, @p1 = 'Track', @p2 = 7/21/2010 5:20:59 PM, @p3 = 'jpregg', @p4 = 'tex0r', @p5 = 0, @p6 = True, @p7 = 7/21/2010 5:21:00 PM, @p8 = '//server/yourmom', @p9 = NULL, @p10 = 5898, @p11 = NULL, @p12 = 0
NHibernate: INSERT INTO Languages (Name) VALUES (@p0); select SCOPE_IDENTITY();@p0 = 'Spanglish'
NHibernate: INSERT INTO Tracks_Credits (TrackID, Index, CreditID) VALUES (@p0, @p1, @p2);@p0 = 20, @p1 = 0, @p2 = 19

I suspect the problem line is this (i’ve run it in SQL and get the same error):

NHibernate: INSERT INTO Tracks_Credits (TrackID, Index, CreditID) VALUES (@p0, @p1, @p2);@p0 = 20, @p1 = 0, @p2 = 19

but what’s throwing me here is that table doesn’t have an “Index” column

there is no “Index” anywhere in my maps either. has anyone seen this?

why is it throwing the ‘index’ in there?

here is the credit map:

public class CreditMap: ClassMap<Credit>
{
    public CreditMap()
    {
        Table("Credits");
        Id(x => x.ID, "CreditId");
        Map(x => x.Email, "Email")
            .Length(1000);
        Map(x => x.Location, "Location")
            .Length(1000);
        Map(x => x.Name, "Name")
            .Length(1000);
        Map(x => x.Role, "Role")
            .Length(1000);
    }
}

and here is the track map:

public class ForeignEntityTypeFilter : FilterDefinition
{
    public ForeignEntityTypeFilter()
    {
        WithName("ForeignEntity")
            .AddParameter("IsType", NHibernate.NHibernateUtil.String);
    }
}

public class TrackMap: ClassMap<Track>
{
    public TrackMap()
    {
        Table("Tracks");
        Id(x => x.ID, "TrackId");
        Map(x => x.ContainsSamples);
        Map(x => x.Description);
        Map(x => x.HasExplicitLyrics);
        Map(x => x.IsCover);
        Map(x => x.Lyrics);
        Map(x => x.Name)
            .Length(1000);
        Map(x => x.OrderIndex);
        References<Genre>(x => x.Genre, "GenreID");
        HasManyToMany<Credit>(x => x.Credits)
            .ChildKeyColumn("CreditID")
            .AsList()
            .ParentKeyColumn("TrackID")
            .Table("Tracks_Credits")
            .Not.Inverse()
            .Cascade.SaveUpdate();
        HasMany<TrackImage>(x => x.Images)
            .Table("Images")
            .KeyColumn("ForeignEntityID")
            .ApplyFilter<ForeignEntityTypeFilter>("'Track' == ForeignEntityType")
            .Not.Inverse()
            .Cascade.SaveUpdate();
        HasManyToMany<Language>(x => x.Languages)
            .ChildKeyColumn("LanguageID")
            .AsList()
            .ParentKeyColumn("TrackID")
            .Table("Tracks_Languages")
            .Not.Inverse()
            .Cascade.SaveUpdate();
        HasManyToMany<MediaFile>(x => x.MediaFiles)
            .ChildKeyColumn("MediaFileID")
            .AsList()
            .ParentKeyColumn("TrackID")
            .Table("Tracks_MediaFiles")
            .Not.Inverse()
            .Cascade.SaveUpdate();
    }
}
  • 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-05-15T22:08:50+00:00Added an answer on May 15, 2026 at 10:08 pm

    The problem is the AsList() mappings for the collections. This maps the collection as an ordered list which requires an index column in the database to maintain the order. You probably want to map them using AsBag().

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

Sidebar

Related Questions

I have read many questions and answers, but I couldn´t find solution for my
I have been trying to solve this issue for a day now and have
I'm using NHibernate and looking for a solution that will allow me to audit
I have read somewhere (can't remeber where and how) that NHibernate 3 allows the
I'm experiencing with NHibernate 3.1.0 (without Fluent yet) on an existing solution in VS2010.
After upgrading the NHibernate and FluentNHibernate DLLs in a project, I'm now getting a
I am building an application using NHibernate. Because I could not add the DLL's
i have just migrated from a single web server environment to a multiwebserver environment
I'm trying to solve a dilemna that has been nagging me for the last
I have a thorny question about transforming Linq Expressions. I had a good search

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.