【发布时间】:2010-02-28 19:13:50
【问题描述】:
我正在使用 Linq to SQL,并阅读了有关尽快关闭数据库连接的博客文章。例如,他们展示了一个被转换为列表的变量(使用 .ToList()),而不是实际返回 Linq 查询。我有以下代码:
public static bool HasPassword(string userId)
{
ProjDataContext db = new ProjDataContext();
bool hasPassword = (from p in db.tblSpecUser
where p.UserID == userId
select p.HasPassword).FirstOrDefault();
return hasPassword;
}
这个查询可以吗?或者数据库连接会保持打开的时间超过必要的时间?
感谢您的建议
【问题讨论】:
标签: c# database performance linq-to-sql database-connection