Question

Hello I am fairly new to visual basic and was wondering if someone could tell me what I'm doing wrong in the ViewData("FirstName") statement??

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

I have the model set up like so:

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

With a dbcontext setup like this:

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
Was it helpful?

Solution

Its been awhile for VB, but I think the syntax should be like the following:

ViewData("FirstName") = db.users.First(function(t) t.NT_id = System.Enviornment.UserName).name_first
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top