'EF Core 5.0 Exception Invalid object name [TableName]
I'm getting an invalid object name error though it's certain the table exists. It is a VB.NET app being converted from 4.6 to Core 5. The 4.6 version finds the tables in the database. There used to be a line of code that initialized the database. It was Me.Database.SetInitializer(Of MyDbContext)(Nothing)
I cannot find anything equivalent in Core 5. To resolve the error I have looked at other Q&A here and tried everything under the sun. Anything else to try?
Public Sub New()
'Original
'Me.Database.Connection.ConnectionString = sqlConString
'Me.Database.SetInitializer(Of MyDbContext)(Nothing)
'New
Me.Database.EnsureCreated()
End Sub
'New
Protected Overrides Sub OnConfiguring(ByVal ob As DbContextOptionsBuilder)
If Not ob.IsConfigured Then
Dim configBuilder As New ConfigurationBuilder()
configBuilder.SetBasePath(Environment.CurrentDirectory).AddJsonFile("appSettings.json")
Dim configSection As IConfigurationSection = configBuilder.Build().GetSection("AppSettings")
ob.UseSqlServer(configSection.GetSection("ConnectionString").Value)
End If
End Sub
Protected Overrides Sub OnModelCreating(ByVal mb As ModelBuilder)
mb.Entity(Of Store)().ToTable("dbo.Store")
mb.Entity(Of StoreAttrib)().ToTable("dbo.Store_Attribute")
mb.Entity(Of GroupStore)().ToTable("dbo.Group_Store")
End Sub
Solution 1:[1]
The answer is, EF Core does not support VB at this time. The application had to be converted to C#.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Scott |
