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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:29:34+00:00 2026-05-16T10:29:34+00:00

I have an Animal class that implements IDomainObject . There is another class, Cat

  • 0

I have an Animal class that implements IDomainObject. There is another class, Cat, that inherits from Animal. I’m using a Table Per Subclass inheritance strategy for my NHibernate mappings and map the CreatedDate and LastModified properties to columns in the Animal table and to columns in the Cat table.

I also use a PreUpdate event handler to assign LastModified with a value.

When I update a property in a Cat object, two UPDATES get sent to the database: one for Animal and one for Cat. However, the UPDATE for Animal is the one that gets the new LastModified value, and the UPDATE for Cat keeps the old value.

This causes some issues when the Cat entity is retrieved again in another Session. It seems that LastModified gets overwritten with the new value (from Animal), effectively marking the entity has dirty, and triggering another UPDATE.

There seems to be something wrong with my overall design, but I’m not sure what it is. What is a better way to go about this?

public class Animal : IDomainObject {
    // ... various properties

    public virtual DateTime CreatedDate { get; set; }
    public virtual DateTime LastModified { get; set; }
    public virtual int Version { get; protected set; }
}

public class Cat : Animal {
    // ... various properties

    public override DateTime CreatedDate { get; set; }
    public override DateTime LastModified { get; set; }
    public override int Version { get; protected set; }
}

public interface IDomainObject {
    DateTime CreatedDate { get; set; }

    DateTime LastModified { get; set; }

    int Version { get; }
}

public bool OnPreUpdate(PreUpdateEvent eventItem) {
    if (!(eventItem.Entity is IDomainObject)) {
        return false;
    }

    var entity = eventItem.Entity as IDomainObject;

    if (entity == null) {
        return false;
    }

    var lastModified = DateTime.Now;

    PersistState(eventItem.Persister, eventItem.State, "LastModified", lastModified);

    entity.LastModified = lastModified;

    return false;
}

private void PersistState(IEntityPersister persister, object[] state, string propertyName, object value) {
    var index = Array.IndexOf(persister.PropertyNames, propertyName);

    if (index == -1) {
        return;
    }

    state[index] = value;
}
  • 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-16T10:29:34+00:00Added an answer on May 16, 2026 at 10:29 am

    Two things I don’t understand:

    1. Why do you override CreatedDate, LastModified and Version in your Cat-class – when they have no new functionality?

    2. Why do you have those three columns in both tables?

    It should be enough to have the three columns/properties in the baseclass – anything else is asking for trouble.

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

Sidebar

Related Questions

Suppose I have a class Dog that inherits from a class Animal . What
Let's suppose I have a class Dog that inherits from class Animal, you might
I have a class that inherits a base class to which another class has
I have a collection of polymorphic objects, all derived from my Animal class: Cat,
I have a legacy database that uses a table per class hierarchy inheritance strategy
Lets say that I have the following code: public class Shelter<A extends Animal, B
I have a very simple scenario, using NHibernate: one abstract base class animal; two
Suppose I have class animal and classes cat and dog extending it. I want
Animals is a dictionary class that contains Animal class objects. DictionaryBase implements IDictionaryEnumerator.GetEnumerator() and
Let's say I am using a framework that has a class called Animal. class

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.