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
The answer is, EF Core does not support VB at this time. The application had to be converted to C#.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.