Database Reference
In-Depth Information
context.BlogPosts.Add(post1);
context.BlogPosts.Add(post2);
context.BlogPosts.Add(post3);
context.SaveChanges();
}
using (var context = new EFRecipesEntities())
{
Console.WriteLine("Blog Posts with comments...(LINQ)");
var posts = from post in context.BlogPosts
where post.Comments.Any()
select post;
foreach (var post in posts)
{
Console.WriteLine("Blog Post: {0}", post.Title);
foreach (var comment in post.Comments)
{
Console.WriteLine("\t{0}", comment.Comments);
}
}
}
Console.WriteLine();
using (var context = new EFRecipesEntities())
{
Console.WriteLine("Blog Posts with comments...(ESQL)");
var esql = "select value p from BlogPosts as p where exists(p.Comments)";
var posts = ((IObjectContextAdapter)context).ObjectContext.CreateQuery<BlogPost>(esql);
foreach (var post in posts)
{
Console.WriteLine("Blog Post: {0}", post.Title);
foreach (var comment in post.Comments)
{
Console.WriteLine("\t{0}", comment.Comments);
}
}
}
Following is the output of the code in Listing 3-10:
Blog Posts with comments...(LINQ)
Blog Post: The Joy of LINQ
Great post, I wish more people would talk about LINQ
Blog Post: LINQ and our Children
You're right, we should teach LINQ in high school!
Blog Posts with comments...(ESQL)
Blog Post: The Joy of LINQ
Great post, I wish more people would talk about LINQ
Blog Post: LINQ and our Children
You're right, we should teach LINQ in high school!
Search WWH ::




Custom Search