我有一个由asp.net mvc和实体框架工作代码首先创建的博客 我想通过两种方式在页面内以两种方式显示排名靠前的N(例如前10位)帖子将在实体框架中计算订单
1-此规则
点 - (DateTime.Now - CreationDate)
点和CreationDate是表后的实体
(我想前N个NE大多数点帖子WES)
2,前N newes后,大多数评论
如何让这两个查询由LINQ到实体?
public class Post
{
public int Id { get; set; }
public string Subject { get; set; }
public string Description { get; set; }
public DateTime CreationDate { get; set; }
public int Point { get; set; }
public virtual IList<Comment> Comments { get; set; }
}
public class Comment
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public Virtual Post Post { get; set;}
}
编辑 我想在查看后的顺序点和CreationDate 这样的查询的功能:
var latestPosts = dbContext.Posts
.OrderByDescending(p => p.Point - (DateTime.Now - p.CreationDate).TotalDays)
.Take(postCount)ToList();
但它引发错误
听起来你需要'OrderBy()',但你的问题有点不清楚。 – gunr2171
你到目前为止有什么? – Tico