Пример #1
0
 static void UpdateArticle(Article article)
 {
     using (var db = new ArticleContext())
     {
         db.Articles.Attach(article);
         db.Entry(article).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Пример #2
0
 static void DeleteArticle(Article article)
 {
     using (var db = new ArticleContext())
     {
         db.Articles.Attach(article);
         db.Articles.Remove(article);
         //db.Entry(article).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
Пример #3
0
        static void CreateArticle(Article article)
        {
            using (var db = new ArticleContext())
            {
                db.Articles.Add(article);

                db.SaveChanges();

            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            var article = new Article
            {
                Title = "Fourth Article",
                Content = "Fourth article content",
                Author = new Author { DisplayName = "Jane Doe", UserName = "******" }
            };

            CreateArticle(article);

            Console.ReadLine();
        }