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

Related Questions

I have a method that looks like this: public static String escape(String text) {
I have a method that starts like this: public static UnboundTag ResolveTag(Type bindingType, string
I have a method like this: private static double ComputePercentage(ushort level, ushort capacity) {
I have this method with a huge switch statement like this: public bool ExecuteCommand(string
I have a static method in my code that I would like somehow to
I have a template class method like that: template<class T> static tmpClass<T>* MakeInstance(T value)
I have static method which returns me as it's name says data from domain
I have a static method that returns a String, but in the event that
I have a static method which sets a variable: static String[] playersNames; public static
I have a class which uses a method in user32.dll: [System.Runtime.InteropServices.DllImport(user32.dll)] private static extern

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.