Database Reference
In-Depth Information
context.SaveChanges();
return comment;
}
}
public void DeleteComment(Comment comment)
{
using (var context = new EFRecipesEntities())
{
context.Entry(comment).State = EntityState.Deleted;
context.SaveChanges();
}
}
}
7.
Finally, add a Windows Console Application to the service project. We'll use this for our client
to test the WCF service. Copy the code from Listing 9-11 into the Program class in the Console
application. Right-click the console application project, select Add Service Reference, and
add a reference to the Service1 service. You will also need to add a project reference to the
class library created in step 1 or expose it through a proxy class from the service.
Listing 9-11. Our Windows Console Application That Serves as Our Test Client
class Program
{
static void Main(string[] args)
{
using (var client = new ServiceReference2.Service1Client())
{
// cleanup previous data
client.Cleanup();
// insert a post
var post = new Post { Title = "POCO Proxies" };
post = client.SubmitPost(post);
// update the post
post.Title = "Change Tracking Proxies";
client.SubmitPost(post);
// add a comment
var comment1 = new Comment {
CommentText = "Virtual Properties are cool!",
PostId = post.PostId };
var comment2 = new Comment {
CommentText = "I use ICollection<T> all the time",
PostId = post.PostId };
comment1 = client.SubmitComment(comment1);
comment2 = client.SubmitComment(comment2);
 
Search WWH ::




Custom Search