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