コード例 #1
0
        public static void Attaching_a_serialized_graph_4()
        {
            Console.WriteLine($">>>> Sample: {nameof(Attaching_a_serialized_graph_4)}");
            Console.WriteLine();

            Helpers.RecreateCleanDatabase();
            Helpers.PopulateDatabase();

            using var context = new BlogsContext();

            var posts = context.Posts.Include(e => e.Blog).ToList();

            #region Attaching_a_serialized_graph_4
            var serialized = JsonSerializer.Serialize(
                posts, new JsonSerializerOptions {
                ReferenceHandler = ReferenceHandler.Preserve, WriteIndented = true
            });
            #endregion

            Console.WriteLine(serialized);

            UpdatePostsFromJson(serialized);
        }
コード例 #2
0
        public static void Attaching_a_serialized_graph_2()
        {
            Console.WriteLine($">>>> Sample: {nameof(Attaching_a_serialized_graph_2)}");
            Console.WriteLine();

            Helpers.RecreateCleanDatabase();
            Helpers.PopulateDatabase();

            #region Attaching_a_serialized_graph_2
            using var context = new BlogsContext();

            var posts = context.Posts.Include(e => e.Blog).ToList();

            var serialized = JsonConvert.SerializeObject(
                posts,
                new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Formatting.Indented
            });

            Console.WriteLine(serialized);
            #endregion

            UpdatePostsFromJsonBad(serialized);
        }