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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:19:30+00:00 2026-05-11T14:19:30+00:00

I have a call that needs to determine if a field has changed. But

  • 0

I have a call that needs to determine if a field has changed. But calling get using that entities id returns the same entity not the prior version.

Entity e = Dao.Get(id); //At this point e.Field is X e.Field = y; Dao.Save(e);  Entity Dao.Get(Guid id) {   return Session.Get(id); }  Entity Dao.Save(Entity e) {    Entity olde = Session.Get(e.Id);    if (e.Field != olde.Field) <--- e.Field == olde.Field so it does not run.      DoBigMethod(e);    return e; } 

How do I handle this situation without adding an onChange method to the Entity class.

  • 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. 2026-05-11T14:19:30+00:00Added an answer on May 11, 2026 at 2:19 pm

    You only know one ‘version’ of the entity: the current one. There is actually only one version of the entity. You have it in memory and you already changed it and forgot the previous state.

    Call get to see the previous database state is dangerous. If changes are already flushed (NHibernate flushes before queries for instance), you get your changes. If you open another session, you see changes from other transactions.

    Are you only interested in one single field? Then you can cache the old value somewhere.

    If this wouldn’t work, you need to tell me more about the reason why you need to know the previous value of this field.

    EDIT:

    Some more ideas:

    • cache the previous state of the field when you get the object, in DAO.Get
    • implement this property that it sets a flag if it changed.
    • consider to make this change an explicit operation called by the client, instead of an implicit operation that is called when the flag changes. For instance, if this flag is called ‘Activated’, implement a ‘Activate’ and ‘Deactivate’ method. This methods change that flag and perform the ‘large set of code’. The flag is read-only for the rest of the world.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have a piece of assembly that needs to call a function with
I have a regex call that I need help with. I haven't posted my
I am begging to use jquery. I have the following call that works in
I have a Guid.NewGuid() call that is creating an Empty Guid. What would cause
I'm creating my own JavaScript Array-like object and I have methods that call closures.
We have some methods that call File.Copy, File.Delete, File.Exists, etc. How can we test
We have a View (call it X) that is the base view called by
I have to call some code in a SharePoint site that runs under the
I am analyzing a .dmp file that was created and I have a call
I have a WCF service that I call from a windows service. The WCF

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.