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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:13:37+00:00 2026-05-23T16:13:37+00:00

Here is a question I frequently ask myself. Here is a code with no

  • 0

Here is a question I frequently ask myself. Here is a code with no repeated code:

private static void delete(Guid teamID, Guid repID)
{
    using (var context = AccesDataRépart.GetNewContext())
    {
        Team_Representant teamRepresentant = getTeamRep(teamID, repID);
        if (teamRepresentant != null)
            context.Team_Representant.DeleteOnSubmit(teamRepresentant);
        context.SubmitChanges();
    }
}

private static Team_Representant getTeamRep(Guid teamID, Guid repID)
{
    using (var context = AccesDataRépart.GetNewContext())
    {
        return (from c in context.Team_Representant
                where c.RepID == repID &&
                      c.TeamID == teamID
                select c).FirstOrDefault();
    }
}

It is normal to have a getTeamRep function, it is used very often. On the other hand, I don’t repeat the query it contains in the Delete function because it would generate extra steps and would generally be slower.

What do you do in such case? Do you repeat the getTeamRep linq query in the Delete function or do you accept this extra workload?

Thanks!

  • 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-23T16:13:37+00:00Added an answer on May 23, 2026 at 4:13 pm

    I never do anything twice :). Make a variable to hold the result of getTeamRep.

    If you’ve never tried it before, get rid of your static stuff and make these all instance methods. Have a Team class and a Rep class, and let the Teams contain their Reps. It might be more fun this way, and it tends to prevent the whole problem of looking up the same object twice.

    It’s a matter of preference. I find instance methods more elegant in most cases, because there are fewer parameters:

     Team team = new Team(teamID);
    
     team.Delete(repID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my situation. I am using two java.util.HashMap to store some frequently used
first question here. I'm developing a program in C# (.NET 3.5) that displays files
Simple question here: is there any way to convert from a jagged array to
C# question here.. I have a UTF-8 string that is being interpreted by a
Newbie question here. I'm in the beginning stages of laying out a site in
The question here is whether something like this already exists or, if not, whether
First question here: it is a very short yet fundamental thing in Java that
First question here so hello everyone. The requirement I'm working on is a small
The question raised from the question here . In order to have search engines
a simple question here Is there a way to change the text click here

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.