我在sql server management studio中更改了我的表名,现在每次mvc trys访问用户表时都会发送dbo.Users而不是dbo.User的查询。
有谁知道如何解决这个问题?
的DbContext:
Imports System.Data.Entity
Imports System.Data.Entity.Infrastructure
Imports System.Data.Entity.ModelConfiguration.Conventions
Public Class MvcDemoContext
Inherits DbContext
Public Sub New()
MyBase.New("name=MvcDemoContext")
End Sub
Private _User As DbSet(Of Controller.User)
Public Property User() As DbSet(Of Controller.User)
Get
Return _User
End Get
Set(value As DbSet(Of Controller.User))
_User = value
End Set
End Property
Private _Forum As DbSet(Of Controller.Forum)
Public Property Forum() As DbSet(Of Controller.Forum)
Get
Return _Forum
End Get
Set(value As DbSet(Of Controller.Forum))
_Forum = value
End Set
End Property
Private _ForumType As DbSet(Of Controller.ForumType)
Public Property ForumType() As DbSet(Of Controller.ForumType)
Get
Return _ForumType
End Get
Set(value As DbSet(Of Controller.ForumType))
_ForumType = value
End Set
End Property
Protected Overrides Sub OnModelCreating(modelBuilder As DbModelBuilder)
modelBuilder.Conventions.Remove(Of PluralizingTableNameConvention)()
modelBuilder.Conventions.Remove(Of IncludeMetadataConvention)()
Database.SetInitializer(Of MvcDemoContext)(Nothing)
MyBase.OnModelCreating(modelBuilder)
End Sub
Public Function ExecuteScalar(ByVal sql As String) As Integer
Try
Using comm = Database.Connection.CreateCommand
Database.Connection.Open()
comm.CommandText = sql
Return CInt(comm.ExecuteScalar)
End Using
Catch ex As Exception
End Try
Return 0
End Function
End Class
控制器:
Public Class ForumController
Inherits System.Web.Mvc.Controller
'
' GET: /Forum
Function Index() As ActionResult
Dim forumCollection As Controller.ForumCollection = New BAL.Forum().GetForums
Return View(forumCollection)
End Function
End Class