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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:19:43+00:00 2026-05-14T20:19:43+00:00

If I have a static method like this private static bool TicArticleExists(string supplierIdent) {

  • 0

If I have a static method like this

    private static bool TicArticleExists(string supplierIdent)
    {
        using (TicDatabaseEntities db = new TicDatabaseEntities())
        {
            if((from a in db.Articles where a.SupplierArticleID.Equals(supplierIdent) select a).Count() > 0)
                return true;                
        }
        return false;
    }

and use this method in various places in foreach loops or just plain calling it numerous times, does it create and open new connection every time?

  1. If so, how can I tackle this? Should I cache the results somewhere, like in this case, I would cache the entire Classifications table in Memory Cache? And then do queries vs this cached object?
  2. Or should I make TicDatabaseEntities variable static and initialize it at class level?
  3. Should my class be static if it contains only static methods? Because right now it is not..
  4. Also I’ve noticed that if I return result.First() instead of FirstOrDefault() and the query does not find a match, it will issue an exception (with FirstOrDefault() there is no exception, it returns null).

Thank you for clarification.

  • 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-14T20:19:44+00:00Added an answer on May 14, 2026 at 8:19 pm
    • new connections are non-expensive thanks to connection caching. Basically, it grabs an already open connection (I htink they are kept open for 2 minutes for reuse).

    • Still, caching may be better. I do really not like the “firstordefault”. Thinks of whether you can acutally pull in more in ONE statement, then work from that.

    For the rest, I can not say anything – too much depends on what you actually do there logically. What IS TicDatabaseEntities? CAN it be cached? How long? Same with (3) – we do not know because we do not know what else is in there.

    If this is something like getting just some lookup strings for later use, I would say….

    • Build a key out of classI, class II, class III
    • load all classifications in (I assume there are only a couple of hundred)
    • Put them into a static / cached dictionary, assuming they normally do not change (and I htink I have that idea here – is this a financial tickstream database?)

    Without business knowledge this can not be answered.

    4: yes, that is as documented. First gives first or an exception, FirstOrDefault defaults to default (empty struct initialized with 0, null for classes).

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

Sidebar

Ask A Question

Stats

  • Questions 492k
  • Answers 492k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you sure the controller and or action you are… May 16, 2026 at 10:27 am
  • Editorial Team
    Editorial Team added an answer You're looking for ^ID: (\d+)(?: Status: (\d+))?$ edit: Since the… May 16, 2026 at 10:27 am
  • Editorial Team
    Editorial Team added an answer TableDefinitions#columns to see what options you can use on creating… May 16, 2026 at 10:27 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a method that starts like this: public static UnboundTag ResolveTag(Type bindingType, string
I have an abstract Catalog class as follows. It has a static method OpenCatalog()
I have come up with the following method to determine is a database is
Okay, newbie multi-threading question: I have a Singleton class. The class has a Static
The example I see everywhere for MVC-style routing is something like this: void Application_Start(object
I have a class that has purely static Methods and properties. I am calling
I have a ComboBox that has its ItemsSource bound to a static List<CustomSettings> of
Do you have a blind spot in programming? I mean is there a common
Good afternoon, I have been working on a dll that can use CORBA to
I'm trying to understand how a while loop looks in IL. I have written

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.