view raw
A Houghton A Houghton - 7 months ago 32 Question

MVC Model creating a table in database rather than using existing

I'm trying to simply access information in a existing database using MVC. The issue is, when i run the code, it creates a table in the database, with a name similar to the table I'm attempting to access with an 's' appended on the end.


Existing table: VXPartsData.

Table created after running application: VXPartsDatas

I've managed to do this in c sharp quite easily, but don't understand where I'm going wrong using VB. If someone could please point me in the right direction, thanks

Imports System.Data.Linq
Imports System.Data.Linq.Mapping
Imports System.ComponentModel.DataAnnotations
Imports System.Data.Entity

Namespace Models

Public Class VXPartsData

Public Property PartNo As String
Public Property CustPart As String
Public Property ShortDesc As String
Public Property Part As String
Public Property Price As Decimal
Public Property DiscCode As String
Public Property Kit As Boolean
Public Property VXCODE As String

End Class

Public Class ProductContext
Inherits DbContext
Public Property VXPartsDatas As DbSet(Of VXPartsData)
End Class

End Namespace


Imports System.Data.Entity
Imports Videx_PB2.Models

Public Class HomeController
Inherits System.Web.Mvc.Controller

Private db As New ProductContext

Function Index() As ActionResult

Return View(db.VXPartsDatas.ToList())

End Function

End Class

Connection String:

<add name="ProductContext" connectionString="server=(localdb)\MSSQLLocalDB; database=VidexPB; integrated security=SSPI" providerName="System.Data.sqlClient" />


In your ProductContext class, add the following code:

protected override void OnModelCreating(ModelBuilder modelBuilder)




EF will not pluralize table names