Repository question. One or many? RRS feed

  • Question

  • User-1154589120 posted

    I have just followed the NerdDinner tutorial which sets up the website using the linq-to-sql dbml file as its model. Later in the tutorial (the video one), it says to refactor this information into repositories and the only access to the database is in the "SqlDinnerRepository.cs" file.

    I am applying the tutorial to a different site so I have than just one model. Should I make a general "SqlRepository.cs" or should I make a different repository for each model. Example: "SqlDinnerRepository.cs", "SqlTagRepository.cs", "SqlCommentRepository.cs" etc?


    using dmbl  System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    namespace StoryHorse.Models {
        public class SqlEntryRepository : IEntryRepository {
            DB db;
            public SqlEntryRepository() {
                db = new DB();
            public IQueryable<Entry> FindAllEntries() {
                return db.Entries;
            public Entry GetEntry(int id) {
                return db.Entries.SingleOrDefault(x => x.entry_id == id);
            public void Add(Entry entry) {
            public void Update(Entry entry) {
            public void Delete(Entry entry) {
    Saturday, February 6, 2010 2:51 PM

All replies

  • User197322208 posted

    Make a repository only for what you want to acces. Think at the repository as if it is a something that you provide to others to use. What you provide in order to use simpler, accurate and easy ?

    Saturday, February 6, 2010 5:29 PM