.Net核心逆向工程與數據庫DNS連接

.net-core asp.net-core asp.net-core-mvc c# entity-framework-core

我的問題很簡單,我已經做了很多尋找答案,但找不到解決辦法。然而,這似乎並不是一個不常見的場景,所以如果我忽略了一些簡單的東西,或者有一個我忽略的參考來解決我的問題,我會感激一些指導!開始...

嘗試通過我的新.Net Core項目連接到現有的異地數據庫。我在這裡遵循逆向工程的說明: https//docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html

這些說明適用於本地計算機上的數據庫,但是當我使用連接字符串將Scaffold-DbContext運行到非現場服務器的數據庫DNS時,它會創建上下文但不創建實體。所以我的上下文類文件如下所示:

using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

namespace CensusApi.Models
{
    public partial class CensusDbContext : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        #warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
        optionsBuilder.UseSqlServer(@"Server=database.dns.org,[port];Database=mydatabase;Integrated Security=False;User ID=myuser;Password=mypassword;");
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
    }

    // Unable to generate entity type for table 'dbo.LANDING_DEMOGRAPHICS_2010'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.LANDING_ECONOMIC_2007_2011'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.LANDING_STATE_FIPS'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.LANDING_ZIP_STATE'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.SAMAIN_ZIP_STATE'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.STAGE_HOUSEHOLDS'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.STAGE_HOUSING_OCCUPANCY'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.STAGE_MEDIAN_AGE'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.STAGE_MEDIAN_INCOME'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.STAGE_POPULATION'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.STAGE_POPULATION_BY_RANGE'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.STAGE_RACE'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.STAGE_RACE_HISPANIC_AND_LATINO'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.STAGE_RELATIONSHIP'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.STAGE_ZIP_STATE'. Please see the warning messages.
    // Unable to generate entity type for table 'dbo.LogShipStatus'. Please see the warning messages.
    }
}

ErrorList窗口引用上面代碼的第11行#warning(即保護連接字符串中潛在敏感信息的警告)。我意識到執行此逆向工程後的下一步是重新定位連接字符串,並且#warning似乎是一般警告,而不是對逆向工程過程的阻礙。

我嘗試過的憑據包括sa用戶和受限用戶。兩者都具有相同的結果,因此它似乎不是權限問題。

我應該使用不同的方法或框架來連接外部服務器嗎?

任何想法或反饋將不勝感激!

一般承認的答案

確保您的表具有主鍵。

我在我的數據庫中只有一個表得到了這個確切的錯誤消息,意識到我忘記了主鍵,並且在我再次運行DbScaffold命令後它運行正常。



Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因