假设我有这样的伪代码使用一些伪 ORM(在我的例子中是 Linq2Db)。
static IEnumerable<A> GetA()
{
using (var db = ConnectionFactory.Current.GetDBConnection())
{
return from a in db.A
select a;
}
}
static B[] DoSmth()
{
var aItems = GetA();
if (!aItems.Any())
return null;
return aItems.Select(a => new B(a.prop1)).ToArray();
}
Connection 什么时候关闭db
?在那种情况下它会完全关闭吗?什么连接会被关闭 - using 语句或 lambda 表达式中的连接?.NET 编译器正在为 lambdas 创建匿名类,因此它将复制到该类的连接。该连接何时关闭?
不知何故,我设法让Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
我实现了查询并且异常消失了。但我想知道这件事是如何运作的。