-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
42 lines (38 loc) · 1.29 KB
/
Program.cs
File metadata and controls
42 lines (38 loc) · 1.29 KB
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
using System;
namespace ef_issue
{
public static class Program
{
public static void Main(string[] args)
{
int id;
// Create a new blog with a post titled "A"
using (var db = new BloggingContext())
{
var blog = new Blog
{
Post = new Post { Title = "A" }
};
db.Add(blog);
db.SaveChanges();
id = blog.Id;
}
// Update blog post title to "B" and add image
using (var db = new BloggingContext())
{
var blog = db.Blogs.Find(id);
// Uncomment this to work around the problem
// var _ = blog.Post;
blog.Post = new Post { Title = "B" };
blog.Post.Images.Add(new Image { Url = "http://example.com/" });
db.SaveChanges();
}
// Fetch blog post title -- should be "B" but is "A"
using (var db = new BloggingContext())
{
var blog = db.Blogs.Find(id);
Console.WriteLine($"Blog post title = {blog.Post.Title}");
}
}
}
}