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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:16:26+00:00 2026-05-23T00:16:26+00:00

I am wondering when I get my object back(Lets say File) and I make

  • 0

I am wondering when I get my object back(Lets say File) and I make these modifications to it.

File.Name = "test";
File.Id = 1;
File.Date = "6/3/2011 12:00:00 am";
File.IsLocked = false

so I get back this file object but Date is not in local time. So when I get it back I right away convert it to local time.

I do this right away(in the same repo method) as this should always be at this point this date should be in local time. I could convert it at a different point what would solve my problem but then the programmer always has to remember once they a File object back they would have to manually call the convertToLocalTime() method.

From past experiences this ended badly with many times it was forgotten to convert to local time. So I really want to leave it there.

So my problem is this

the File now looks like this once returned

File.Name = "test";
    File.Id = 1;
    File.Date = "6/3/2011 5:00:00pm";
    File.IsLocked = false

Now I have to take this object and change File.IsLocked To True

File.Name = "test";
    File.Id = 1;
    File.Date = "6/3/2011 5:00:00pm";
    File.IsLocked = true

Now the problem is I need to save this but I don’t want to save the local time. I want to ignore this for this one commit(there maybe other times when the Date needs to be saved but not in this instance)

Can I somehow tell nhibernate to not save the converted date?

  • 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-23T00:16:27+00:00Added an answer on May 23, 2026 at 12:16 am

    If you use an interceptor class you can call convertToLocalTime() without let the programmer have to!

    public class TestInterceptor
      : EmptyInterceptor, IInterceptor
    {
        private readonly IInterceptor innerInterceptor;
    
        public TestInterceptor(IInterceptor innerInterceptor)
        {
            this.innerInterceptor = this.innerInterceptor ?? new EmptyInterceptor();
        }
    
    
     public override bool OnSave(object entity, 
                                    object id, 
        object[] state, 
        string[] propertyNames, 
        IType[] types)
        {
            if ( entity is yourType) {
                //call convertToLocalTime()
            }
            return this.innerInterceptor.OnSave(entityName, id,state,propertyNames,types);
        }
    
    
    }
    

    hth

    updated

    Interceptors are classes allows you to override base nhibernate methods like OnSave, OnLoad… that are called for every entity.

    Look here:

    Implementing NHibernate Interceptors

    and you can configure it fluently:

    return Fluently.Configure()
               ...
                .ExposeConfiguration(c =>{c.Interceptor = new TestInterceptor(c.Interceptor ?? new EmptyInterceptor());})
                ...
                .BuildConfiguration();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

newbie here .. wondering why in the table i get something called '[object node]'
I am wondering how to get a process run at the command line to
I was wondering if in Java I would get any odd behaviour if I
I was wondering if anyone can help me get started with creating a room
Just wondering if there is any way (in C) to get the contents of
I'm wondering if it's possible to get a handle on running instances of a
I was wondering if there was somewhere I could get some starter kit /
I was wondering if there was a way to get at the raw HTTP
I'm wondering if there are any simple ways to get a list of all
I was wondering if there is a JOptionPane where you can get multiple inputs

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.