We added a new table to our SQL Server database called Occupation.
From the ASP.NET Web Form project, I can not seem to access it.
Imports System.Data.Entity
Public Class CCDBContext
Inherits DbContext
Public Sub New()
MyBase.New("name=CCDBContext")
End Sub
Public Property ClaimDetail_CSR() As DbSet(Of ClaimDetail_CSR)
Public Property CSR_Filter() As DbSet(Of CSR_Filter)
Public Property CSR_AnalysisCodes() As DbSet(Of CSR_AnalysisCodes)
Public Property Occupations() As DbSet(Of Occupation)
Protected Overrides Sub OnModelCreating(modelBuilder As System.Data.Entity.DbModelBuilder)
MyBase.OnModelCreating(modelBuilder)
End Sub
End Class
The class for Occupation:
Public Class Occupation
Public Property ClassCode As String
Public Property Description As String
<KeyAttribute()>
Public Property idOccupation As Integer
Public Property OccupationName As String
Public ReadOnly Property Occupation As String
Get
Dim pt1 As String = String.Format("{0}", ClassCode).Trim()
Dim pt2 As String = String.Format("{0}", OccupationName).Trim()
Dim pt3 As String = String.Format("{0}", idOccupation)
Return String.Format("{0} - {1} - {2}", pt1, pt2, pt3)
End Get
End Property
End Class
I need to link it into my Linq query:
dim query = (
From cd as ClaimDetail_CSR In ClaimQuery
Join oc As Occupation In db.Occupations On cd.idOccupation Equals oc.idOccupation
Group Join ac As CSR_AnalysisCodes In db.CSR_AnalysisCodes On cd.ClaimKey Equals ac.Claimkey Into MatchedClaim = Group
From mc In MatchedClaim.DefaultIfEmpty()
Select cd.ClientID, cd.ClaimKey, cd.Region, cd.Office, cd.Department, cd.ClaimNumber,
You can see where I want to join the new Occupation table above.
Whenever I run the code, however, I get this exception:
System.Data.Entity.Core.EntityCommandExecutionException: 'An error occurred while executing the command definition. See the inner exception for details.'
Inner Exception
SqlException: Invalid object name 'dbo.Occupations'.[/quote]
From what I have gathered in my online searches, the suggested thing to do is to open the .edmx file, right-click somewhere in the empty space, and select 'update model from database'.
https://stackoverflow.com/q/28479785/27599767
However, my project does not have an .edmx file. It simply has the DBContext files.
How do I update my DBContext to include the new SQL table?