【发布时间】:2018-02-19 14:00:44
【问题描述】:
运行我的项目后,Visual Studio 在我的 Index.cshtml 中显示了这个 System.NotSupportedException
这是我的 HomeController
public class HomeController : BaseController
{
public ActionResult Index()
{
var events = this.db.Events
.OrderBy(e => e.StartDateTime)
.Where(e => e.IsPublic)
.Select(e => new EventViewModel()
{
Id = e.Id,
Title = e.Title,
Duration = e.Duration,
Author= e.Author.FullName,
Location = e.Location
});
var upcomingEvents = events.Where(e => e.StartDateTime > DateTime.Now);
var passedEvents = events.Where(e => e.StartDateTime <= DateTime.Now);
return View(new UpcomingPassedEventsViewModel()
{
UpcomingEvents = upcomingEvents,
PassedEvents = passedEvents
});
}
}
}
这是我的 EventViewModel.cs
public class EventViewModel
{
public int Id { get; set; }
public string Title { get; set; }
public DateTime StartDateTime { get; set; }
public TimeSpan? Duration { get; set; }
public string Author { get; set; }
public string Location { get; set; }
}
【问题讨论】:
-
您的活动似乎只包含 id、标题、持续时间、作者和位置 - 没有开始日期时间
-
您必须为您的
EventViewModel课程提供代码。StartDateTime属性很可能未映射到数据库列。但是要检查我们是否需要代码。 -
我添加了我的 EventViewModel
标签: c# visual-studio linq notsupportedexception