我正在使用Oracle.ManagedDataAccess
(v. 4.122.19.1) 和实体框架 (v. 6.0.0.0)。
我创建了一个像这样的简单上下文:
public class FooContext : DbContext
{
public FooContext() : base(new OracleConnection(Connection.connection),true)
{
Database.SetInitializer<FooContext>(null);
Configuration.LazyLoadingEnabled = false;
}
}
和测试方法:
[TestMethod]
private static void TestIsConnectionOpen()
{
using (var db = new FooContext())
{
Assert.AreEqual(ConnectionState.Open, db.Database.Connection.State);
}
}
我预计,在这种情况下,连接将自动打开,例如https://github.com/entityframeworktutorial/EF6-DBFirst-Demo,但测试失败。
有人可以向我解释为什么吗?
Connection.connection
是一个有效的连接字符串,因为当我将测试方法更改为:
[TestMethod]
private static void TestIsConnectionOpen()
{
using (var db = new FooContext())
{
db.Database.Connection.Open();
Assert.AreEqual(ConnectionState.Open, db.Database.Connection.State);
}
}
然后测试通过了。