我得到一个无效的对象名称错误,虽然它是确定的表存在。它是一个VB。. NET应用程序从4.6转换到Core 5。4.6版本在数据库中查找表。过去有一行代码用于初始化数据库。这是Me.Database。SetInitializer (MyDbContext)(什么)
我在Core 5中找不到任何相同的内容。为了解决这个错误,我查看了这里的其他Q&A,并尝试了所有方法。还有什么可以尝试的吗?
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
答案是,EF Core目前不支持VB。必须将应用程序转换为c#。