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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:02:51+00:00 2026-06-12T08:02:51+00:00

I am unable to get the below update to execute in the context of

  • 0

I am unable to get the below update to execute in the context of nhibernate.

using(ITransaction transaction = session.BeginTransaction())
{
    // FIRST I'm GETTING A LIST OF ITEMS IN A MANNER LIKE THIS
    var itemsToDelete = session.QueryOver<Item>()
                                   .Where(i => i.ReferenceObject.Id == otherIdValue)
                                   .List<Item>();

    // THEN I"M LOOPING THROUGH THEM
    for(itemToDelete in itemsToDelete)
    {

        session.Delete(itemToDelete);

        using (iDB2Command command = (iDB2Command)_session.Connection.CreateCommand())
        {
            command.CommandText = "update TABLE_NAME set sequence = (sequence - 1) where id = @someId and sequence > @sequenceNumberDeleted";
            command.DeriveParameters();
            command.Parameters["@someId"].Value = idValue;
            command.Parameters["@sequenceNumberDeleted"].Value = itemToDelete.Sequence;
        }
    }

    transaction.commit()
}

The problem seems to be with the sequence = (sequence – 1). Everytime the routine is called NHibernate is throwing an “unexpected row count” exception. While researching most articles I found related to this exception were caused by a trigger on the table updating other rows. In this case there aren’t any triggers on the table. Additionally if I replace sequence = 5 or some other constant the update statement executes without any problems.

DATE TIME [10] ERROR App.Controllers.AController - Unexpected row count: 2; expected: 1
DATE TIME [10] ERROR App.Controllers.AController -    at NHibernate.AdoNet.Expectations.BasicExpectation.VerifyOutcomeNonBatched(Int32 rowCount, IDbCommand statement)
   at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Int32 j, Object obj, SqlCommandInfo sql, ISessionImplementor session, Object[] loadedState)
   at NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Object obj, ISessionImplementor session)
   at NHibernate.Action.EntityDeleteAction.Execute()
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
   at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
   at NHibernate.Engine.ActionQueue.ExecuteActions()
   at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
   at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
   at NHibernate.Impl.SessionImpl.Flush()
   at NHibernate.Transaction.AdoTransaction.Commit()
   at App.Controllers.AController.AMethod(Int32[] otherIdValues, Int32 someIdValue, String someReferenceValue) in    <path>\App\Controllers\AController.cs:line 117

Can someone help point me in the right direction?

EDIT:
Diego is quite right. This is what I get for rushing.
The actual call to this code is inside a transaction and then I’m calling commit on the transaction.

  • 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-12T08:02:52+00:00Added an answer on June 12, 2026 at 8:02 am

    I have since found the cause of the issue. The actual statements were not being generated sequentially as I thought they would be. Instead the update command was executing prior to the delete command and thus the delete command was throwing the unexpected row count exception, not the update command as I previously thought.

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

Sidebar

Related Questions

I have only recently started using CakePHP and have been unable to get validation
I working on app what should get list of users from db and update
I am unable to get the following code to work, using this page for
I have three tables - Context, Session and User. And below are their simplified
I get unable to open database file when executing rc = sqlite3_open(test.db, &db); ??
I am unable to get the correct title for this, please change the title
I am unable to get a highcharts plugin to render a chart in a
I'm unable to get this jquery statement to work on page load but it
I'm unable to get the Central Maven repo index. I'm running Netbeans 7.0.1 and
I am unable to get a Javascript callback to work with gmaps4_rails when the

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.