Which code segment should you insert at line 07?

You use Microsoft .NET Framework 4 to develop an application that uses WCF Data Services to
persist entities from the following Entity Data Model.

You create a new Blog instance named newBlog and a new Post instance named newPost as shown
in the following code segment. (Line numbers are included for reference only.)
01 Dim newBlog As Blog = New Blog()
02 Dim newPost As Post = New Post ()
03 —
04 Dim serviceUri As Uri – New Uri(“—”)
05 Dim context As BlogsEntities =
06 New BlogsEntities (serviceUri) 07
You need to ensure that newPost is related to newBlog through the Posts collection property and
that newPost and newBlog are sent to the service. Which code segment should you insert at line 07?

You use Microsoft .NET Framework 4 to develop an application that uses WCF Data Services to
persist entities from the following Entity Data Model.

You create a new Blog instance named newBlog and a new Post instance named newPost as shown
in the following code segment. (Line numbers are included for reference only.)
01 Dim newBlog As Blog = New Blog()
02 Dim newPost As Post = New Post ()
03 —
04 Dim serviceUri As Uri – New Uri(“—”)
05 Dim context As BlogsEntities =
06 New BlogsEntities (serviceUri) 07
You need to ensure that newPost is related to newBlog through the Posts collection property and
that newPost and newBlog are sent to the service. Which code segment should you insert at line 07?

A.
newBlog.Posts.Add(newPost)
context.AttachTo(“Blogs”, newBlog)
context.AttachTo(“Posts”, newPost)
context.SaveChanges(SaveChangesOptions.Batch)

B.
newBlog.Posts.Add(newPost)
context.UpdateObject(newBlog)
context.UpdateObject(newPost)
context.SaveChanges(SaveChangesOpt ions.Batch)

C.
newBlog.Posts.Add(newPost)
context.AddToBlogs(newBlog)
context.AddToPosts(newPost)
context.SaveChanges(SaveChangesOpt ions.Batch)

D.
context.AttachLink(newBlog, “Posts”, newPost) context.SaveChanges(SaveChangesOptions.Batch)

Explanation:
Attaching and Detaching objects
(http://msdn.microsoft.com/en-us/library/bb896271.aspx)



Leave a Reply 0

Your email address will not be published. Required fields are marked *