-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Top-level statements for EFGetStarted (#3865)
Migrate EFGetStarted sample to using top-level statements feature. (https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements)
- Loading branch information
1 parent
7d14982
commit bed89fd
Showing
2 changed files
with
24 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,30 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace EFGetStarted; | ||
using var db = new BloggingContext(); | ||
|
||
internal class Program | ||
{ | ||
private static void Main() | ||
{ | ||
using var db = new BloggingContext(); | ||
// Note: This sample requires the database to be created before running. | ||
Console.WriteLine($"Database path: {db.DbPath}."); | ||
|
||
// Note: This sample requires the database to be created before running. | ||
Console.WriteLine($"Database path: {db.DbPath}."); | ||
// Create | ||
Console.WriteLine("Inserting a new blog"); | ||
db.Add(new Blog { Url = "http://blogs.msdn.com/adonet" }); | ||
db.SaveChanges(); | ||
|
||
// Create | ||
Console.WriteLine("Inserting a new blog"); | ||
db.Add(new Blog { Url = "http://blogs.msdn.com/adonet" }); | ||
db.SaveChanges(); | ||
// Read | ||
Console.WriteLine("Querying for a blog"); | ||
var blog = db.Blogs | ||
.OrderBy(b => b.BlogId) | ||
.First(); | ||
|
||
// Read | ||
Console.WriteLine("Querying for a blog"); | ||
var blog = db.Blogs | ||
.OrderBy(b => b.BlogId) | ||
.First(); | ||
// Update | ||
Console.WriteLine("Updating the blog and adding a post"); | ||
blog.Url = "https://devblogs.microsoft.com/dotnet"; | ||
blog.Posts.Add( | ||
new Post { Title = "Hello World", Content = "I wrote an app using EF Core!" }); | ||
db.SaveChanges(); | ||
|
||
// Update | ||
Console.WriteLine("Updating the blog and adding a post"); | ||
blog.Url = "https://devblogs.microsoft.com/dotnet"; | ||
blog.Posts.Add( | ||
new Post { Title = "Hello World", Content = "I wrote an app using EF Core!" }); | ||
db.SaveChanges(); | ||
|
||
// Delete | ||
Console.WriteLine("Delete the blog"); | ||
db.Remove(blog); | ||
db.SaveChanges(); | ||
} | ||
} | ||
// Delete | ||
Console.WriteLine("Delete the blog"); | ||
db.Remove(blog); | ||
db.SaveChanges(); |