ASP.NET Linq访问嵌套的select元素&绑定到中继器

时间:2014-10-28 06:05:07

标签: c# asp.net linq

ASP.NET中的Repeater绑定 我希望嵌套的选择元素绑定到转发器。这是我的代码:

var ret = (from post in db.Posts.ToList()
    orderby post.PostedDate descending
    select new
    {
        Message = post.Message,
        PostedBy = post.PostedBy,
        PostedByName = post.UserProfile.UserName,
        PostedDate = post.PostedDate,
        PostId = post.PostId,
        PostComments = from comment in post.PostComments.ToList() 
            orderby comment.CommentedDate
            select new
            {
                CommentedBy = comment.CommentedBy,
                CommentedByName = comment.UserProfile.UserName,
                CommentedDate = comment.CommentedDate,
                CommentId = comment.CommentId,
                Message = comment.Message,
                PostId = comment.PostId
            }
        }).AsEnumerable();

在aspx页面上我的帖子得到了绑定<%#Eval("PostedBy")%>但是我想要在特定帖子发表评论,我无法绑定评论元素,如commentedbycommentidcommentdate<%#Eval("CommentedBy")%>但它并没有受到约束。

请帮我解决这个问题,如何将CommentedDate和其他元素绑定到评论框布局?

0 个答案:

没有答案