我在控制器中调用下面的方法。
var comments = _blogService.GetBlogComments(bc.CommentParentID);//Controller code
班级代码:
public virtual IList<BlogComment> GetBlogComments(int CommentParentId)
{
if (CommentParentId != 0)
{
var query = from bc in _blogCommentRepository.Table
where bc.CommentParentID == CommentParentId
select bc;
var comments = query.ToList();
return comments;
}
else
return null;
}
我收到错误
var query = from bc in _blogCommentRepository.Table
where bc.CommentParentID == CommentParentId
select bc;][1]
答案 0 :(得分:1)
绑定的第一件事是您在_blogCommentRepository
方法中使用的GetBlogComments
变量是null
。因此,请确保在使用之前初始化此变量:
_blogCommentRepository = new ...