我有一个带有评论图片的aspx网站。表的结构是:
Table name: Images
int id (Primary Key)
varcharmax path(path of the image)
Table name: Comments
int picid; (Linked to image id)
Text text;
我需要使用Entity Framework选择前10个评论图像。怎么可能?
答案 0 :(得分:1)
应该是这样的:
var result = (from img in db.Images
order by img.Comments.Count() descending
select img).Take(10);
或者,如果像我一样,你更喜欢其他语法(使用方法)
var result = db.Images
.OrderByDescending(img => img.Comments.Count())
.Take(10);
答案 1 :(得分:0)
这将选择前10名:
var result = (
from i in db.Images
order by i.Comments.Count() descending
select i).Take(10);