.Net Core逆向工程与数据库DNS连接
.Net Core Reverse-Engineering with database DNS connection
我的问题很简单,我搜索了很多答案,但一直没有找到解决方案。然而,这似乎不是一种罕见的情况,所以如果我忽略了一些简单的事情,或者那里有一个我忽略的参考来解决我的问题,我将不胜感激提供一些指导!开始了...
试图通过我的新 .Net Core 项目连接到现有的异地数据库。我已按照此处的逆向工程说明进行操作:https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html
这些说明适用于我本地计算机上的数据库,但是当我 运行 Scaffold-DbContext 将连接字符串连接到异地服务器的数据库 DNS 时,它会创建上下文但不会创建实体。所以我的上下文 class 文件如下所示:
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 window 指的是上述代码第 11 行的#warning(即保护连接字符串中潜在敏感信息的警告)。我意识到进行此逆向工程后的下一步是重新定位连接字符串,#warning 似乎是一个通用警告,而不是对逆向工程过程的阻碍。
我试过的凭据包括 sa 用户和受限用户。两者的结果相同,所以这似乎不是权限问题。
我应该使用其他方法或框架来连接到外部服务器吗?
如有任何想法或反馈,我们将不胜感激!
确保您的 table 有主键。
我的数据库中只有一个 table 收到了这条确切的错误消息,我意识到我忘记了主键,在我再次 运行 DbScaffold 命令后它 运行 很好.
我的问题很简单,我搜索了很多答案,但一直没有找到解决方案。然而,这似乎不是一种罕见的情况,所以如果我忽略了一些简单的事情,或者那里有一个我忽略的参考来解决我的问题,我将不胜感激提供一些指导!开始了...
试图通过我的新 .Net Core 项目连接到现有的异地数据库。我已按照此处的逆向工程说明进行操作:https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html
这些说明适用于我本地计算机上的数据库,但是当我 运行 Scaffold-DbContext 将连接字符串连接到异地服务器的数据库 DNS 时,它会创建上下文但不会创建实体。所以我的上下文 class 文件如下所示:
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 window 指的是上述代码第 11 行的#warning(即保护连接字符串中潜在敏感信息的警告)。我意识到进行此逆向工程后的下一步是重新定位连接字符串,#warning 似乎是一个通用警告,而不是对逆向工程过程的阻碍。
我试过的凭据包括 sa 用户和受限用户。两者的结果相同,所以这似乎不是权限问题。
我应该使用其他方法或框架来连接到外部服务器吗?
如有任何想法或反馈,我们将不胜感激!
确保您的 table 有主键。
我的数据库中只有一个 table 收到了这条确切的错误消息,我意识到我忘记了主键,在我再次 运行 DbScaffold 命令后它 运行 很好.