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?
Thanks
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) {
db.Entries.InsertOnSubmit(entry);
}
public void Update(Entry entry) {
db.SubmitChanges();
}
public void Delete(Entry entry) {
db.Entries.DeleteOnSubmit(entry);
db.SubmitChanges();