我一直在努力弄清楚为什么这个代码在foreach循环之前处理dbcontext。任何线索将不胜感激。谢谢!
[TestMethod]
public void CreatePostAddComment()
{
IQueryable<Post> thePost;
using (var _context = new BlogRepository())
{
_context.AddPost(GetTestPost());
var retrivePost = _context.GetPostByName("TestPost1");
thePost = retrivePost;
}
foreach (var post in thePost)
{
using (var _dbContext = new BlogRepository())
{
_dbContext.AddComment(GetTestComment(post));
}
}
}