Vb.net VB填充控制器列表

Vb.net VB填充控制器列表,vb.net,class,properties,Vb.net,Class,Properties,我正在使用这个示例VB代码,使用MS Web API将一组数据行返回到html页面中的表中,它工作得非常好 Public Class CalendarEventsController Inherits ApiController Private CalendarEvents As CalendarEvent() = New CalendarEvent() { New CalendarEvent() With { .id = 1, .even

我正在使用这个示例VB代码,使用MS Web API将一组数据行返回到html页面中的表中,它工作得非常好

 Public Class CalendarEventsController
    Inherits ApiController

    Private CalendarEvents As CalendarEvent() = New CalendarEvent() {
      New CalendarEvent() With {
      .id = 1,
      .eventName = "Event 1"
    }, New CalendarEvent() With {
            .id = 2,
            .eventName = "Event 2"
        }}
    ' GET api/<controller>
    Public Function GetCalendarEvents() As IEnumerable(Of CalendarEvent)
        Return CalendarEvents
    End Function
End Class

您已经能够从数据库检索数据了吗?如果是,你是如何做到的?最明智的选择是使用LINQ查询来创建CalendarEvent对象,该查询几乎将一个循环封装在一行中,但详细信息取决于您所拥有的数据结构,例如类型化数据集或EF上下文,或者可能是已经从此类数据中派生出来的DTO。jmchiliney:谢谢-这很好。我已经有了用于DB检索的linq-EF6代码,但没有意识到linq查询将处理我的html端代码的数据转换细节:$.getJSON(“api/CalendarEvents”)。非常感谢-这真的很容易。我只是在学习这个Web api的东西,有时看不到明显的问题。
     Public Class CalendarEventsController
    Inherits ApiController
    Public Function GetCalendarEvents() As IEnumerable(Of EventCalendar)
        Dim myContext As New RoutesEntities()
        Return From eventlist In myContext.EventCalendars Select eventlist
    End Function
End Class