1 回答
TA贡献1789条经验 获得超10个赞
您选择匿名对象
List<EventGalleryViewModel> list = db.EventGallerys.GroupBy(eg => new
{
EventId = eg.EventId,
Title = eg.Title,
EventDate = eg.EventDate,
Description = eg.Description,
ThumbImage = eg.ThumbImage
})
.OrderByDescending(eg => eg.Key.EventDate)
.Take(5)
.AsEnumerable()
.Select(eg => new EventGalleryViewModel()
{
EventId = eg.Key.EventId,
Day = eg.Key.EventDate.ToString("D"),
Month = eg.Key.EventDate.ToString("MMM"),
Year = eg.Key.EventDate.ToString("yyyy"),
Title = eg.Key.Title,
Description = eg.Key.Description,
ThumbImage = eg.Key.ThumbImage
}).toList();
return View(list);
我希望这能解决你的问题
- 1 回答
- 0 关注
- 156 浏览
添加回答
举报