-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
executable file
·46 lines (40 loc) · 1.5 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Linq;
using System.Collections.Generic;
namespace EFGetStarted
{
internal class Program
{
private static void Main()
{
using (var db = new BloggingContext())
{
// Note: This sample requires the database to be created before running.
// 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();
// 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();
// Bulk
List<Post> posts = new List<Post>();
posts.Add(new Post { Title = "1", Content = "One" });
posts.Add(new Post { Title = "2", Content = "Two" });
db.BulkInsertOrUpdate(posts);
}
}
}
}