Created
February 14, 2012 19:28
-
-
Save lancscoder/1829463 to your computer and use it in GitHub Desktop.
Revisions
-
lancscoder created this gist
Feb 14, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ // Entity Framework - Delete using (var db = new BlogContext()) { var post = db.Posts.Find(1); db.Posts.Remove(post); db.SaveChanges(); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ // Entity Framework – Filtered List using (var db = new BlogContext()) { var posts = db.Posts.Where(p => p.Text.Contains("Some Value")).ToList(); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ // Entity Framework - Insert using (var db = new BlogContext()) { var post = new Post { Title = "Title 1", Text = "Text 1", PublishDate = DateTime.Now }; db.Posts.Add(post); db.SaveChanges(); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ // Entity Framework – Simple List using (var db = new BlogContext()) { var posts = db.Posts.ToList(); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ // Entity Framework - Single using (var db = new BlogContext()) { var post = db.Posts.Find(1); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ // Entity Framework - Update using (var db = new BlogContext()) { var post = db.Posts.Find(1); post.Title = "New Title"; db.SaveChanges(); }