예제 #1
0
 public void Delete(int id)
 {
     using (var context = new DataContext())
     {
         context.Authors.Remove(context.Authors.First(x => x.Id == id));
         context.SaveChanges();
     }
 }
예제 #2
0
        public Author Save(Author author)
        {
            using (var context = new DataContext())
            {
                if (author.Id == 0)
                {
                    context.Authors.Add(author);
                }
                else
                {
                    context.Entry(author).State = EntityState.Modified;
                    context.Authors.AddOrUpdate(author);
                }
                context.SaveChanges();

            }
            return author;
        }