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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:04:15+00:00 2026-06-03T06:04:15+00:00

Everyone knows this using (var db = new DatabaseEntites()) { var row = db.SomeTable.SingleOrDefault(r

  • 0

Everyone knows this

using (var db = new DatabaseEntites())
{
    var row = db.SomeTable.SingleOrDefault(r => r.Id == 5)
}

I planned to create a static class with a static method like this

public static class SomeTableRepository
{
   public static class GetSomeTableRow(DatabaseEntities db, int id)
   {
        return db.SomeTable.SingleOrDefault(r => r.Id == 5);
   }
}

and the first code would then look like this

using (var db = new DatabaseEntites())
{
    var row = SomeTableRepository.GetSomeTableRow(db, id);
}

If this would be a web app…would that kind of programming be ok…or could that kind of programming cause some trouble?…or is this perfectly good code 🙂

  • 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-06-03T06:04:17+00:00Added an answer on June 3, 2026 at 6:04 am

    As Kirk said, I think the only gain is minor readability. However, if you add this in front of your first parameter and make this an extension method, then you might gain some readability for potential readers of your code:

    UPDATE

    I also noticed that public static class GetSomeTableRow would not compile. I changed it to be more generic and less confusing for future readers (class to YourClassName)

    public static class SomeTableRepository
    {
       public static YourClassName GetSomeTableRow(this DatabaseEntities db, int id)
       {
            return db.SomeTable.SingleOrDefault(r => r.Id == 5);
       }
    }
    
    ...
    
    database.GetSomeTableRow(id);
    

    Furthermore, you could rename this to make it read more like what it actually is:

    database.GetOneRowFromSomeTableById(id);
    

    Yes, it is lengthy, but the only reason to abstract such a simple method as SingleOrDefault would be to make the code even readable at a glance. The ById part is debatable since the parameter is named id (and it makes it seem redundant), however that only shows up while coding with intellisense. You could leave it out (or take it down to just By without Id…but that leaves too much for each implementer IMO)

    database.GetOneRowFromSomeTable(id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using code similar to below: var image = new Image(); image.src = http://youtube.com/favicon.ico;
I saw someone using this in one answer: void methodA(const int*& var); I couldn't
OK...I am hoping this is a classic problem that everyone knows the answer to
Edit: This has since been solved. Thanks to everyone who helped. Invoking the method
Been using Django for < 1yr now, but this one is new-to-me. Hopefully someone?
Everyone knows that you should be only using tables for semantic purposes, to markup
Everyone knows that there is cache in session. This cache generally could be cleared
Sorry in advance everyone for this question as I know the cascading select boxes
Everyone knows the = sign. SELECT * FROM mytable WHERE column1 = column2; However,
as everyone knows Windows does paths with backslashes where Unix does paths with forward

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.