当我说这个
using (Entities db = new Entities())
{
return db.TableName.AsQueryable().ToList();
}
Run Code Online (Sandbox Code Playgroud)
我是否绕过了使用块的功能,因为我返回了一些内容,并且该方法在退出using块之前退出,因此我认为using块不会用于其目的并处置资源.
它是否正确?
我有这种方法应该从称为ENTRY的表(&EntitySet)中获取最新消息的发布
///方法获取“天”作为参数,用于新的TimeSpan(days,0,0,0); !!
using (Entities db = new Entities())
{
var entries = from ent in db.ENTRY
where ent.DATECREATE.Value > DateTime.Today.Subtract(new TimeSpan(days, 0, 0, 0))
select new ForumEntryGridView()
{
id = ent.id,
baslik = ent.header,
tarih = ent.entrydate.Value,
membername = ent.Member.ToString()
};
return entries.ToList<ForumEntryGridView>();
}
Run Code Online (Sandbox Code Playgroud)
在这里,DATECREATED在数据库中为空。我无法在此查询中放置“如果” ...以任何方式进行检查?提前Thx