MVC3 ViewData Visual Basic问题

时间:2013-08-28 17:37:20

标签: asp.net-mvc-3 entity-framework viewdata

你好我对visual basic相当新,并且想知道是否有人可以告诉我在ViewData(“FirstName”)语句中我做错了什么?

Public Class HomeController
Inherits System.Web.Mvc.Controller

Private db As cs_dev_ccmetrics_apps = New cs_dev_ccmetrics_apps

Protected Overrides Sub OnActionExecuted(filterContext As ActionExecutedContext)

    'APP INFO
    '--------------------------
    ViewData("Version") = "0.1.7"
    ViewData("RevDate") = "08/20/2013"

    ViewData("FirstName") = 
        Select name_first
        From users
        Where NT_id = System.Environment.UserName


End Sub

我的模型设置如下:

Imports System
Imports System.Collections.Generic

Partial Public Class users
    Public Property id As Integer
    Public Property domain_id As Byte
    Public Property NT_id As String
    Public Property emp_id As Integer
    Public Property ssn As String
    Public Property pwd As String
    Public Property admin_role As Byte
    Public Property name_last As String
    Public Property name_first As String
    Public Property last_login As Nullable(Of Date)
    Public Property failed_attempts As Byte
    Public Property active As Boolean
    Public Property dt_updated As Date

End Class

使用这样的dbcontext设置:

Imports System
Imports System.Data.Entity
Imports System.Data.Entity.Infrastructure

Partial Public Class cs_dev_ccmetrics_apps
    Inherits DbContext

    Public Sub New()
        MyBase.New("name=cs_dev_ccmetrics_apps")
    End Sub

    Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
        Throw New UnintentionalCodeFirstException()
    End Sub

    Public Property app_log() As DbSet(Of app_log)
    Public Property ref_AdminRole() As DbSet(Of ref_AdminRole)
    Public Property ref_apps() As DbSet(Of ref_apps)
    Public Property ref_domains() As DbSet(Of ref_domains)
    Public Property user_apps() As DbSet(Of user_apps)
    Public Property users() As DbSet(Of users)

End Class

1 个答案:

答案 0 :(得分:0)

对于VB来说已经有一段时间了,但我认为语法应如下所示:

ViewData("FirstName") = db.users.First(function(t) t.NT_id = System.Enviornment.UserName).name_first