Ejemplo n.º 1
0
 static void UpdateArticle(Article article)
 {
     using (var db = new ArticleContext())
     {
         db.Articles.Attach(article);
         db.Entry(article).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 3
0
        static void CreateArticle(Article article)
        {
            using (var db = new ArticleContext())
            {
                db.Articles.Add(article);

                db.SaveChanges();

            }
        }
Ejemplo n.º 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();
        }