【发布时间】:2017-02-27 12:38:08
【问题描述】:
我有一个称为 BigDataOverview 的数据库架构。我的大部分应用程序已经连接到称为 AdminDb 的不同架构。
我还有一个与我的 AdminDb 架构完美集成的 .Net Core 应用程序。
我的辅助架构有 13 个不同的表,它们以数字命名,还有一个名为“SimpleDataOverview”的表。
我现在想将此辅助架构添加到我的应用程序中,以便我可以{ get; } 将数据显示在我的应用程序中。
我已经在 appsettings.json 中设置了我的 ConnectionString:
"ConnectionStrings": {
"DefaultConnection":"server=<placeholder>;database=AdminDB;sslmode=none;",
"OverviewDataConnection": "server=<placeholder>;database=BigDataOverview;sslmode=none;"
}
所有 13 个以数字为名称的表在字段(列)方面彼此相同。因此,我创建了一个模型来匹配所有这些:NumberTableModel.cs
public class NumberTableModel
{
[Key]
public int RowID { get; }
public int SensorID { get; }
public DateTime ReadingDate { get; }
public int ReadingCount { get; }
public float ApproxDataSize { get; }
public Time ReadingTime { get; }
public string JsonData { get; }
public long LastUpdate { get; }
public string Source { get; }
}
我还创建了一个 DbContext:DevOpsDbContext
public class DevOpsDbContext : DbContext
{
public DevOpsDbContext(DbContextOptions<DevOpsDbContext> options) : base(options)
{
}
public DbSet<NumberTableModel> _353224061929963 { get; set; }
public DbSet<NumberTableModel> _353224061929964 { get; set; }
public DbSet<NumberTableModel> _353224061929965 { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<NumberTableModel>().ToTable("353224061929963");
modelBuilder.Entity<NumberTableModel>().ToTable("353224061929964");
modelBuilder.Entity<NumberTableModel>().ToTable("353224061929965");
}
}
我已经在我的 Startup.cs 中设置了它:
services.AddDbContext<DevOpsDbContext>(options =>
options.UseMySql(Configuration.GetConnectionString("OverviewDataConnection")));
但是,当我尝试使用 Entity Framework 创建带有视图的Controller 时,Visual Studio 会抱怨以下错误消息:
我相信我会这样做....如果能提供任何帮助,我将不胜感激。
【问题讨论】:
标签: c# asp.net asp.net-mvc entity-framework connection-string