예제 #1
0
 public IList <Note> GetAllNotes()
 {
     using (var db = new NoteContext(_connectionString))
     {
         return(db.Notes.ToList());
     }
 }
예제 #2
0
        public void Delete(long id)
        {
            using (var db = new NoteContext(_connectionString))
            {
                var noteToDelete = db.Notes.First(note => note.Id == id);

                db.Notes.DeleteOnSubmit(noteToDelete);
                db.SubmitChanges();
            }
        }
예제 #3
0
 public SqlNoteRepository()
 {
     using (var db = new NoteContext(_connectionString))
     {
         if (!db.DatabaseExists())
         {
             db.CreateDatabase();
         }
     }
 }
예제 #4
0
 public void Add(string title, string contents)
 {
     using (var db = new NoteContext(_connectionString))
     {
         db.Notes.InsertOnSubmit(
             new Note
         {
             Title    = title,
             Contents = contents
         });
         db.SubmitChanges();
     }
 }