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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:18:01+00:00 2026-05-27T05:18:01+00:00

In the course of adding exception handling for occasional SQL problems (random timeouts, etc.)

  • 0

In the course of adding exception handling for occasional SQL problems (random timeouts, etc.) to my various queries in my EF4 web app, I’ve really got to refactor the common exception handling code into one function to maintain. But I do lots of different kinds of LINQ queries on different entities.

My first pass at this is close, I think. In this example, I have two overloaded functions that take different kinds of parameters that do a very similar database query:

public bool check_person(string name)
{
    return CheckInternal(people.Where(x => x.user_name == name));
}

public bool check_person(Guid ID)
{
    return CheckInternal(people.Where(x => x.user_ID == ID));
}

protected bool CheckInternal(IQueryable<people> peepQuery)
{
     try
     {
         return(peepQuery).Any(); //causes actual db query
     }
     catch (Exception ue)
     { blah blah retry blah blah }
}

So I’m just pushing the actual enumeration to the CheckInternal function that has all kinds of fancy exception handling and retry logic in it which is totally independent of the query or even the table being queried.

Now the drawback here is that I can only pass in an IQueryable<people> but I want to be able to pass in an IQueryable on lots of different entity types other than the people type.

I tried wrapping my head around lambdas to allow me to pass in any kind of query on any entity type and have just one wiz-bang exception handler to maintain, but I’m just not there yet with my lambda and delegate knowledge. I can’t figure it out.

Can someone give me a hint? What if I had another function that wanted to do a query on the widgets table and pass it to CheckInternal? It’s critical that the actual enumeration only happen in the CheckInternal function since that’s where the exception will be thrown.

  • 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-27T05:18:02+00:00Added an answer on May 27, 2026 at 5:18 am

    If the return type stays a boolean and you just want to query different entities in your example you could make CheckInternal generic and change the signature as follows:

    protected bool CheckInternal<T>(IQueryable<T> someQuery)
    {
       //..
    }
    

    Then you could call it like this

    public bool check_person(string name)
    {
        return CheckInternal<People>(people.Where(x => x.user_name == name));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on adding exceptions and exception handling to my OSS application. Exceptions
I simply want to load a GWT(Google Web Toolkit) app by adding a script
I have a home grown web server in my app. This web server spawns
I'm taking a cloud computing course and have a few problems that I am
When adding JQuery to hide a class it of course waits for the page
When adding user input to a web page, it should (unless it's HTML of
After adding java.sql.Blob field to one of my objects the hibernate persistence manager is
Of course I am aware of Ajax, but the problem with Ajax is that
Of course most languages have library functions for this, but suppose I want to
Of course, there are a whole range of possible errors relating to document validity,

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.