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

The Archive Base Latest Questions

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

Is there a way in NHibernate to make it generate SQL which adds a

  • 0

Is there a way in NHibernate to make it generate SQL which adds a value to a column as in update column1 = column1 + 10?

This is for concurrent updates when two connections could be updating the value and select followed by update would not be work correctly.

The other way seems to have the following lines in the mapping file:

optimistic-lock="dirty"
dynamic-update="true"

Then the code would look something like this:

byte tryAgain = 3;
while( --tryAgain >= 0 )
{
    try { 
        using (ISession s = OpenSession())
        using (ITransaction tx = s.BeginTransaction())
        {
            var person = s.Query<X>().Where(o => o.Y == z ).FirstOrDefault();
            if( person != null ) {
                person.Column1 = person.Column1 + myValue;
                s.Update( person );
            }
            break;
        }
    } catch ( StaleObjectException ) {
        if( tryAgain == 0 ) {
            throw;
        }
    }
}

The amount of code to handle this situation is not too bad, but
update column1 = column1 + x is such a nice and basic SQL feature that it would be cool if there was a way to e.g. express the fact that the field of the mapped class in the mapping represents a delta rather than an absolute value.

Thanks is advance,

Tymek

  • 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-26T22:36:09+00:00Added an answer on May 26, 2026 at 10:36 pm

    using HQL

    s.CreateQuery("UPDATE person SET Property1=Property1 + :p1")
        .SetParameter("p1", myValue)
        .ExecuteUpdate();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to make an Nhibernate query generate Sql that has columnName<>'value' rather
Is there any way to make NHibernate.Linq generate a like query on an integer
Is there a way to use Rhino.Commons with Fluent Nhibernate, (in particular AutoMapping)? Many
Using Castle ActiveRecord / NHibernate: Is there a way you can force an ICriterion
Do you know if there is a way of using Amazon SimpleDB with NHibernate?
In PL/SQL Developer v7.1.x, is there way way to ignore large data types in
i'm sure there's a way to do this Does anybody know if there is
I wonder if there is a way to ignore child-objects with NHibernate where a
Is there a way to get at runtime the number of calls NHibernate is
Is there any way to make Hibernate evict both an entity and all of

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.