【发布时间】:2017-04-28 00:59:42
【问题描述】:
我正在使用 EF6,并创建了这两个模型:
public class Publication
{
public int Id { get; set; }
public string Name { get; set; }
public List<Product> Products { get; set; }
}
public class ViewLog
{
public int Id { get; set; }
public int? UserId { get; set; }
[ForeignKey("UserId")]
public User.User User { get; set; }
public int? SessionId { get; set; }
[ForeignKey("SessionId")]
public User.Session Session { get; set; }
public int PublicationId { get; set; }
[ForeignKey("PublicationId")]
public Publication.Publication Publication { get; set; }
public DateTime Created { get; set; }
}
每次访问出版物时,我都会在 ViewLog 表中创建一条新记录。 现在,使用 Linq,我需要按过去 24 小时内每个出版物的 ViewLogs(访问)数量排序所有出版物。 (如果 Publication 没有 ViewLogs,它们也需要出现,但显然在具有 viewlogs 的发布之后)
【问题讨论】:
-
你有什么尝试吗?你可以试试
Left Join和Group BY和Having Count。 -
是的,我知道如何用 SQL 来获得这个,但我在 Linq 中找不到类似的东西。
标签: c# asp.net entity-framework linq lambda