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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:43:04+00:00 2026-05-20T05:43:04+00:00

Hey all, I seem to have these types of methods everywhere. The method below

  • 0

Hey all, I seem to have these types of methods everywhere.

The method below wants to do these simple tasks:

  1. Open a DB connection (IntLMPDB object)
  2. Read a simple record off a small DB table (the DB table is keyed with strings, because each string is the name of method, so I want just one row of each in the table), the rest of the row is a series of timestamps that tell me when things happned.
  3. If you can’t find the record, then return an exception because there’s nothing that can be done.
  4. If you find the record, look at the second date if it’s just plain missing, then set to true because this is the first ever run.
  5. Or finally get to the meat, if the first date is greater than the second set to True because it’s been updated and it’s time to run. Else if not, set to False because there’s no update yet.

So here’s the code… What I am trying to do is pare this down to the best and quickest way to run through these checks. I am not concerned about like DB connection issues or anything like that.

    private static bool isLastIntervalNewerThanDB(string muiMethod)
    {
       using (var db = new IntLMPDB())
        {
            // Try to load a matching record.
            LastIntervalUpdated liRec = db.LastIntervalUpdateds.FirstOrDefault(rec => rec.method == muiMethod);
            // If it could not be loaded, exit because there's no way to determine if we should run.
             if (liRec == null) { throw new Exception(string.Format("Could NOT find LastIntervalUpdated record for muiMethod: {0}", muiMethod)); }
            else
            {
                // we have a valid interval record, so lets check that it has been updated since the last webPostTime.
                // put another way, there are three datetime values in the LastIntervalUpdated table. First is the
                // interval itself, second is the retrievalTime and third is the webPostTime. Whenever the MUI is 
                // checked for a new interval if one is found then the code updates the retrievalTime to the current
                // instant in time. This tells us what the last interval this application found on its last run was.
                // The thrid value is the webPostTime, this time instant is only updated by this very method we're in
                // right here. We can use this logic: if the retrievalTime is greater than the webPostTime then there's
                // a newer interval that we haven't yet processed and inserted into the databse. So we should run the
                // method below and update ALL of the syncable values into the databse. Then we'll set the dbPostTime to 
                // the current instance. As it goes, if this program then runs again before the interval is updated
                // then the dbPostTime will be greater than the retrieval time and we'll know to do nothig. Simple Right? :)

                // or check here includes a NULL check on dbPostTime because it's possible that dbPostTime is NULL,
                // in the example of the first time the system runs. It might have run a LastUpdate sync and not yet
                // done this method, so dbPostTime would be NULL. None of the other columns are allowed to be null.
                if (liRec.dbPostTime_EST == null || liRec.retrievalTime_EST > liRec.dbPostTime_EST)
                { return true; }
                else { return false; }
            }
       }
    }
  • 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-20T05:43:05+00:00Added an answer on May 20, 2026 at 5:43 am

    I think the logic is fine. I would suggest that you do something like this to improve readability*:

    private static bool isLastIntervalNewerThanDB(string muiMethod)
    {
       using (var db = new IntLMPDB())
        {
            LastIntervalUpdated liRec 
                = db.LastIntervalUpdateds
                        .FirstOrDefault(rec => rec.method == muiMethod);
    
            if (liRec == null) 
            { 
                throw new Exception(
                    string.Format("Could NOT find LastIntervalUpdated record for muiMethod: {0}", muiMethod)); 
            }
    
            return liRec.dbPostTime_EST == null 
                || liRec.retrievalTime_EST > liRec.dbPostTime_EST;        
       }
    }
    

    *While readability is subjective I would argue that an else after if (liRec == null) only adds unnecessary nesting and the final conditional can be collapsed into a single expression. Also never underestimate a well-placed newline within a long expression – it can make all the difference betwee readable and unreadable code.

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

Sidebar

Related Questions

Hey all, I have something of an interesting requirement for my project. I need
Hey all - I have an app where I'm authenticating the user. They pass
Hey all. I have a server written in java using the ServerSocket and Socket
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
Hey all- I have looked this up on here and Google but none of
Hey all, I am not quite getting why this doesn't seem to be working.
Hey all i am trying to get my code below to work in order
Hey all, my Computational Science course this semester is entirely in Java. I was
Hey all. Newbie question time. I'm trying to setup JMXQuery to connect to my
Hey all. We're sending quite a few emails (around 23k) using IIS6 SMTP service

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.