我的WCF方法尝试从数据库中获取一些数据。最后调用这个方法:
public override IQueryable<Apartment> GetAll()
{
return base.GetAll().Include("Pictures").Include("Infos");
}
public virtual IQueryable<T> GetAll()
{
return DbSet;
}
但是当它尝试打开与数据库的连接时似乎发生了错误。我收到错误The underlying provider failed on Open."
。我可以在WCF配置文件中以某种方式指定允许数据库连接,或者在我的项目中允许WCF连接到我的数据库。还是有其他解决方案?
public Base()
{
DataContext = new Context();
this.DbSet = DataContext.Set<T>();
DataContext.Configuration.ProxyCreationEnabled = false;
DataContext.Configuration.LazyLoadingEnabled = false;
}
...
public class Context:DbContext
{
public Context()
: base("DefaultConnection")
{
}
答案 0 :(得分:0)
为Context
创建一个类部分扩展名。在该覆盖中,构造函数传入一个不同的连接字符串(也需要在配置中作为该名称)来基于诸如
public partial class Context
{
public Context(string targetDBConnection) : base(targetDBConnection) {}
}