簡體   English   中英

EF Core 5.0 異常無效的對象名稱 [TableName]

[英]EF Core 5.0 Exception Invalid object name [TableName]

盡管確定該表存在,但我收到了無效的對象名稱錯誤。 它是一個正在從 4.6 轉換到 Core 5 的 VB.NET 應用程序。4.6 版本在數據庫中查找表。 曾經有一行代碼用於初始化數據庫。 是 Me.Database.SetInitializer(Of MyDbContext)(Nothing)

我在 Core 5 中找不到任何等效的東西。為了解決這個錯誤,我在這里查看了其他問答,並在陽光下嘗試了一切。 還有什么可以嘗試的嗎?

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#。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM