【发布时间】:2018-08-03 15:56:14
【问题描述】:
我需要使用实体框架进行分组的前 5 个 LINQ 查询,下面是我需要 LINQ 查询的 sql 查询。
select top 5
EventId,
Datename(day, EventDate) as Day,
convert(varchar(3), EventDate, 100) as Month,
Datename(yy, EventDate) as year,
Title, Description, ThumbImage
from
EventGalleries
group by
EventId, Title, EventDate, Description, ThumbImage
order by
EventDate desc
这是我在 SQL Server 中的表结构:
这是我的操作方法,我需要一个 linq 查询来将列表返回到我的视图:
public ActionResult Gellery()
{
var list = db.EventGallerys.ToList();// i need linq query here in place of this list
return View(list);
}
这是我的模型类:
public class EventGallery
{
[Key]
public int Sno {get;set;}
public string ImageName { get; set; }
public string ThumbImage { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime EventDate { get; set; }
public string EventId { get; set; }
public string GalleryType { get; set; }
public string IP { get; set; }
public string SubmittedBy { get; set; }
public DateTime GalleryCreatedDate { get; set; }
public string Status { get; set; }
// Sno,ImageName,ThumbImage,Title,Description,EventDate,GalleryCreatedDate,EventId,GalleryType,Status
public EventGallery()
{
GalleryCreatedDate = DateTime.Now;
Status = "Active";
}
}
提前感谢您的努力。
【问题讨论】: