您好,我对 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