Which code segment should you insert at line 06?

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 Blog newBlog = neu Blog();
02 Post neuPost = neu Post ();
03 –
04 Uci serviceUri = new Uri (“… “);
05 BlogsEntities context = new BlogsEntities(serviceUri);
06
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 06?

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 Blog newBlog = neu Blog();
02 Post neuPost = neu Post ();
03 –
04 Uci serviceUri = new Uri (“… “);
05 BlogsEntities context = new BlogsEntities(serviceUri);
06
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 06?

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

B.
newBlog.Posts.Add(newPost);
context.AddToBlogs(newBlog);
context.AddToPosts(newPost);
context.SaveChanges(SaveChangesOptions.Batch);

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

D.
newBlog.Posts.Add(newPost);
context.UpdateObject(newBlog);
context.UpdateObject(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 *