我一直在我的数据访问层有以下类型的代码设置(组成示例)
public static class LoadData
{
private static SomeDataContext db = new SomeDataContext();
public static void LoadData(DropDownList ddl)
{
(from ls in db.MyLookup
select ls).OrderBy(ls=>ls.theId).ToList()
.ForEach(ls=>ddl.Items.Add(new ListItem(ls.theText, ls.theValue.ToString())));
}
}
DataContext 是否“智能”足以自行清理,还是我应该用using
语句包装我的查询以确保连接已关闭?