问题
EDIT: I came across an old question that has my problem. Entity Framework conflict with same table name from different databases one of the solutions is using Code first for an existing database and change the namespace. I did use the code first and the generated classes were missing the LOB class. please guys, any ideas what to do?
I'm trying to add multiple databases to my project. when I tried to add the second database using the ADO.net model .the generated context class of the first database gave an error.
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
the problem is in model1, the name of the table is Lob. the name of the table in phoneScreen model, is LOB I would appreciate any guidance .I'm really lost and this project is going to have 6 different databases
the generated context for the phone screen
//------------------------------------------------------------------------------
// <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; }
}
}
the connection string in the webconfig
<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="data source=.\instance;initial catalog=Phone_Screening;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
the generated context for the exit app database
//------------------------------------------------------------------------------
// <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; }
}
}
the connection string in the webconfig
<add name="ExitApplication2015Entities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=.\instance;initial catalog=ExitApplication2015;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Exit application lob
phone screening LOB
来源:https://stackoverflow.com/questions/59825254/accessing-multiple-databases-from-the-same-project-issue