我正在使用Linq to SQL并在博客文章中阅读有关快速打开关闭数据库连接的信息。作为一个例子,他们展示了如何将一个变量转换为一个列表(使用.ToList()),而不是实际执行Linq查询。以下是我的一些代码:`pu`
我正在使用
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;
}
using (ProjDataContext db = new ProjDataContext()) {
bool hasPassword = (from p in db.tblSpecUser
where p.UserID == userId
select p.HasPassword).FirstOrDefault();
return hasPassword;
}
我正在使用Linq to SQL并在博客文章中阅读有关快速打开关闭数据库连接的信息。作为一个例子,他们展示了如何将一个变量转换为一个列表(使用.ToList()),而不是实际执行Linq查询。以下是我的一些代码:`pu`
我正在使用
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;
}
using (ProjDataContext db = new ProjDataContext()) {
bool hasPassword = (from p in db.tblSpecUser
where p.UserID == userId
select p.HasPassword).FirstOrDefault();
return hasPassword;
}