C# 从同一项目问题访问多个数据库

C# 从同一项目问题访问多个数据库,c#,sql-server,asp.net-mvc,visual-studio-2017,ado.net,C#,Sql Server,Asp.net Mvc,Visual Studio 2017,Ado.net,编辑:我遇到了一个老问题,这是我的问题。 其中一种解决方案是先对现有数据库使用代码,然后更改名称空间。我确实首先使用了代码,生成的类缺少LOB类。伙计们,你们知道怎么做吗 我正在尝试将多个数据库添加到我的项目中。当我尝试使用ADO.net模型添加第二个数据库时,第一个数据库生成的上下文类给出了一个错误 Error CS0246 The type or namespace name 'Lob' could not be found (are you missing a using direc

编辑:我遇到了一个老问题,这是我的问题。 其中一种解决方案是先对现有数据库使用代码,然后更改名称空间。我确实首先使用了代码,生成的类缺少LOB类。伙计们,你们知道怎么做吗

我正在尝试将多个数据库添加到我的项目中。当我尝试使用ADO.net模型添加第二个数据库时,第一个数据库生成的上下文类给出了一个错误

Error   CS0246  The type or namespace name 'Lob' could not be found (are you missing a using directive or an assembly reference?)   Manage_account  C:\Users\tmp187115\source\repos\Exit application\Manage_account\Models\Model1.Context.cs    30  Active

问题在model1中,表的名称是Lob。 phoneScreen模型中的表名为LOB 我会很感激任何指导。我真的迷路了,这个项目将有6个不同的数据库

为手机屏幕生成的上下文

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Manual changes to this file may cause unexpected behavior in your application.
//     Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Manage_account.Models
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class Phone_ScreeningEntities2 : DbContext
    {
        public Phone_ScreeningEntities2()
            : base("name=Phone_ScreeningEntities2")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public virtual DbSet<Accounts> Accounts { get; set; }
        public virtual DbSet<LOB> LOB { get; set; }
        public virtual DbSet<Offer_Letter> Offer_Letter { get; set; }
    }

}
//------------------------------------------------------------------------------
//

电话屏蔽线

如果我能看到你的context.cs的一个片段,那就容易多了。在your context.cs中,您是如何引用Lob实体的?Hi@LinkedListT,我编辑了这篇文章,并在web配置中添加了一段上下文。如果您希望我添加其他内容,只需说soAre you connecting to the correct db?找不到Lob表。@LinkedList很抱歉回复太晚。当我连接第二个模型时,无法看到lob表。我试图刷新模型。此时无法看到第二个模型LOB表。我从昨天开始就在这个循环中,我不知道该怎么做,您使用的是什么版本的EF,您能告诉我们两个数据库中表Lob和Lob的具体结构吗?
    <add name="Phone_ScreeningEntities2" connectionString="metadata=res://*/Models.phoneScreen.csdl|res://*/Models.phoneScreen.ssdl|res://*/Models.phoneScreen.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\instance;initial catalog=Phone_Screening;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Manual changes to this file may cause unexpected behavior in your application.
//     Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Manage_account.Models
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class ExitApplication2015Entities : DbContext
    {
        public ExitApplication2015Entities()
            : base("name=ExitApplication2015Entities")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public virtual DbSet<AccountOrOU> AccountOrOUs { get; set; }
        public virtual DbSet<Department> Departments { get; set; }
        public virtual DbSet<Lob> Lobs { get; set; }
    }
}
    <add name="ExitApplication2015Entities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\instance;initial catalog=ExitApplication2015;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />