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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:41:29+00:00 2026-05-15T12:41:29+00:00

OK, I’m always trying to improve the way I code, because it’s my passion.

  • 0

OK, I’m always trying to improve the way I code, because it’s my passion. I have a .dbml file (LINQ to SQL), and I use it to access my SQL Server database.

Imagine, if you will, that you have a Person table in your database and you want to provide a way to delete, add, and modify a Person record.

The way I’m handling things currently is creating classes called PersonRepository, CarRepository, DocumentRepository, etc. For each table in my database, I create a repository class.

These repository classes generally consist of something similar to this:

MyDatabaseContext db = new MyDatabaseContext();

public Person GetPersonByID(int id)
{
    return db.Person.Where(p => p.ID == id);
}

Pretty much the same for the basic CRUD functionality of each table.

If I need something more specific, for example “Sergio, I need a list of all people born between x and y”; then I just add the method to the PersonRepository class.

public List<Person> GetPeopleFromDOB(DateTime x, DateTime y)
{
    // Do the logic here.
}

Another idea I had was to create a DataAccess.cs class and have all of these methods in there (we would be talking around 4-5 methods per tables in existence) and have them divided by regions.

What are the more knowledgeable programmers doing and what suggestions would you offer for an eager young programmer (I’m 20 years old)?

  • 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-15T12:41:29+00:00Added an answer on May 15, 2026 at 12:41 pm

    Here are the problems with what you’re doing above:

    Using List when you should be using IQueryable

    Why use AsQueryable() instead of List()?

    Basically, you should never get data until you need it. With your approach you’re always getting data from the database and subsequent LINQ queries will act on all data. Why not just build up queries and let LINQ refine things down to where it only gets what you need and only when you need it?

    Using Methods when Extension Methods would be perfect

    You are creating a utility class of methods with things like GetPeopleFromDOB. Why not make this an Extension method? If you make all of them return IQueryable you could use them in succession as well. E.g. GetPeople().StatusEnabled().BornInJuly().AgeIsGreaterThan( 57 ); Also, if you must do this at least consider doing so in a partial class or a static utility class.

    Consider Using ActiveRecord/Repository Pattern as the root

    http://compiledexperience.com/blog/posts/Implementing-an-ActiveRecord-pattern-in-Linq-to-SQL

    Right now you’re creating several hardcoded repositories, but you should be basing them off of Repository?

    Why not use validators?

    If you’re using ASP.NET MVC, validation is part and parcel, however with webforms you can also use the Data Annotation Validators.

    http://adventuresdotnet.blogspot.com/2009/08/aspnet-webforms-validation-with-data.html

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

Sidebar

Related Questions

No related questions found

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.