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 632559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:05:24+00:00 2026-05-13T20:05:24+00:00

I have the following mappings: public class SecurityMap : ClassMap<Security> { public SecurityMap() {

  • 0

I have the following mappings:

public class SecurityMap : ClassMap<Security>
    {
        public SecurityMap()
        {
            Table("Security");
            CompositeId().KeyProperty(k => k.Id, "SecurityId").KeyProperty(k => k.EndDate);
            Map(x => x.LastUpdateUser);
            References(x => x.Company).Columns("CompanyId", "EndDate");
            References(x => x.PrimaryListing).Columns("PrimaryListingId", "EndDate");
         }
    }

public class ListingMap : ClassMap<Listing>
    {
        public ListingMap()
        {
            Table("Listing");
            CompositeId().KeyProperty(k => k.Id, "ListingID").KeyProperty(k => k.EndDate);
            References(x => x.Security).Columns("SecurityId","EndDate");
        }
    }

 public class CompanyMap : ClassMap<Company>
    {
        public CompanyMap()
        {
            Table("Company");
            CompositeId().KeyProperty(k => k.Id, "CompanyID").KeyProperty(k => k.EndDate);
            HasMany(x => x.Securities).KeyColumns.Add("CompanyId", "EndDate");
        }       
    }

When I attempt to run this test:

[Test]
public void can_update_a_security()
{
    var repo = IoC.Resolve<ISecurityRepository>();
    int someSecurity = 1;
    using (var work = IoC.Resolve<IUnitOfWorkManager>().Current)
    {
        Security security = repo.Get(someSecurity);
        security.ShouldNotBeNull();
        security.LastUpdateUser = "Dirk Diggler" + DateTime.Now.Ticks;
        repo.Save(security);
        work.Commit();
    }
}

I get the following error deep in the bowels of NHibernate:

Execute
System.IndexOutOfRangeException: Invalid index 6 for this
SqlParameterCollection with Count=6.
at System.Data.SqlClient.SqlParameterCollection.RangeCheck(Int32
index)
at System.Data.SqlClient.SqlParameterCollection.GetParameter(Int32
index)
at System.Data.Common.DbParameterCollection.System.Collections.IList.get_Item(Int32
index)
s:\NHibernate\NHibernate\src\NHibernate\Type\DateTimeType.cs(65,0):
at
NHibernate.Type.DateTimeType.Set(IDbCommand
st, Object value, Int32 index)
s:\NHibernate\NHibernate\src\NHibernate\Type\NullableType.cs(180,0):
at
NHibernate.Type.NullableType.NullSafeSet(IDbCommand
cmd, Object value, Int32 index)
s:\NHibernate\NHibernate\src\NHibernate\Type\NullableType.cs(139,0):
at
NHibernate.Type.NullableType.NullSafeSet(IDbCommand
st, Object value, Int32 index,
ISessionImplementor session)
s:\NHibernate\NHibernate\src\NHibernate\Type\ComponentType.cs(213,0):
at
NHibernate.Type.ComponentType.NullSafeSet(IDbCommand
st, Object value, Int32 begin,
ISessionImplementor session)
s:\NHibernate\NHibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs(2393,0):
at
NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object
id, Object[] fields, Object rowId,
Boolean[] includeProperty, Boolean[][]
includeColumns, Int32 table,
IDbCommand statement,
ISessionImplementor session, Int32
index)
s:\NHibernate\NHibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs(2754,0):
at
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object
id, Object[] fields, Object[]
oldFields, Object rowId, Boolean[]
includeProperty, Int32 j, Object
oldVersion, Object obj, SqlCommandInfo
sql, ISessionImplementor session)
s:\NHibernate\NHibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs(2666,0):
at
NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object
id, Object[] fields, Object[]
oldFields, Object rowId, Boolean[]
includeProperty, Int32 j, Object
oldVersion, Object obj, SqlCommandInfo
sql, ISessionImplementor session)
s:\NHibernate\NHibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs(2940,0):
at
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object
id, Object[] fields, Int32[]
dirtyFields, Boolean
hasDirtyCollection, Object[]
oldFields, Object oldVersion, Object
obj, Object rowId, ISessionImplementor
session)
s:\NHibernate\NHibernate\src\NHibernate\Action\EntityUpdateAction.cs(78,0):
at
NHibernate.Action.EntityUpdateAction.Execute()
s:\NHibernate\NHibernate\src\NHibernate\Engine\ActionQueue.cs(130,0):
at
NHibernate.Engine.ActionQueue.Execute(IExecutable
executable)
s:\NHibernate\NHibernate\src\NHibernate\Engine\ActionQueue.cs(113,0):
at
NHibernate.Engine.ActionQueue.ExecuteActions(IList
list)
s:\NHibernate\NHibernate\src\NHibernate\Engine\ActionQueue.cs(147,0):
at
NHibernate.Engine.ActionQueue.ExecuteActions()
s:\NHibernate\NHibernate\src\NHibernate\Event\Default\AbstractFlushingEventListener.cs(241,0):
at
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource
session)
s:\NHibernate\NHibernate\src\NHibernate\Event\Default\DefaultFlushEventListener.cs(19,0):
at
NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent
event)
s:\NHibernate\NHibernate\src\NHibernate\Impl\SessionImpl.cs(1478,0):
at NHibernate.Impl.SessionImpl.Flush()
s:\NHibernate\NHibernate\src\NHibernate\Transaction\AdoTransaction.cs(187,0):
at
NHibernate.Transaction.AdoTransaction.Commit()
at lambda_method(ExecutionScope , ITransaction )

Now the interesting thing is if I comment out the reference to Company or PrimaryListing in the SecurityMap, I don’t get the error. It doesn’t seem to matter which I comment out. The error only happens when I have both.

When the update actually goes through NHProf shows me this update:

UPDATE Security
SET    LastUpdateUser = '2010-02-19T08:09:24.00' /* @p0 */,
       CompanyId = 54199 /* @p1 */,
       EndDate = '9999-12-31T00:00:00.00' /* @p2 */
WHERE  SecurityId = 1 /* @p3 */
       AND EndDate = '9999-12-31T00:00:00.00' /* @p4 */

I am not sure why it is updating CompanyId and EndDate, but I suspect it is related.

Any one have ideas? Work arounds would be greatly appreciated.

  • 1 1 Answer
  • 1 View
  • 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-13T20:05:24+00:00Added an answer on May 13, 2026 at 8:05 pm

    Yes its a common problem, you are using the Column "EndDate" twice in your mapping definition (for both Company and PrimaryListing) and that is not allowed. One of them has to go, or have an additional EndDate column (one for each association)

    check this too
    nHibernate 2.0 – mapping a composite-id *and* many-to-one relationship causes "invalid index" error

    and
    http://devlicio.us/blogs/derik_whittaker/archive/2009/03/19/nhibernate-and-invalid-index-n-for-this-sqlparametercollection-with-count-n-error.aspx

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

Sidebar

Ask A Question

Stats

  • Questions 383k
  • Answers 383k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer someDateInstance.ToString("dd.MM.yyyy HH:mm:ss") May 14, 2026 at 10:41 pm
  • Editorial Team
    Editorial Team added an answer Cant you do this: Create a permission set which has… May 14, 2026 at 10:41 pm
  • Editorial Team
    Editorial Team added an answer You need to add a manifest (resource) to your exe.… May 14, 2026 at 10:41 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.