. net核心逆向工程与数据库DNS连接

本文关键字:DNS 连接 数据库 核心 逆向工程 net | 更新日期: 2023-09-27 18:12:39

我的问题相当简单,我已经做了很多搜索的答案,但一直未能找到一个解决方案。这似乎不是一个不寻常的情况,然而,所以如果我忽略了一些简单的东西,或者有一个参考资料,我已经忽略了解决我的问题,我将非常感谢一些指导!这里是…

在尝试连接到一个现有的,离线数据库通过我的新。net Core项目。我在这里遵循逆向工程的说明:https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html

这些指令适用于本地机器上的数据库,但是当我使用连接字符串运行Scaffold-DbContext到离线服务器的数据库DNS时,它创建了上下文,但没有实体。所以我的context类文件是这样的

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用户和受限制的用户。两者都有相同的结果,所以这似乎不是权限问题。

是否有一个不同的方法或框架,我应该使用连接到外部服务器?

任何想法或反馈将非常感谢!

. net核心逆向工程与数据库DNS连接

确保你的表有主键。

我的数据库中只有一个表,我得到这个确切的错误消息,意识到我忘记了主键,在我再次运行DbScaffold命令后,它运行良好。