我需要带回几个用户特定的数据集来绑定到经常(重新)加载的搜索页面的下拉列表(可能无法利用回发数据)。我想打一次数据库,并在必要时从会话数据中填充下拉列表,而不是再次从数据库中获取它。
当我设置会话时(下面的最后一行),它会存储评估结果,还是会引用会话每次重新运行查询?如果是后一种情况,在设置会话之前强制评估的最佳方法是什么,同时仍然保持使用匿名类型?
public class CustomClass
{
public IQueryable Results1 { get; set; }
public IQueryable Results2 { get; set; }
}
public static CustomClass GetResults()
{
var results1 = (
from t in Table
select new
{
t.Id,
t.Value
};
var results2 = (
from t in Table
select new
{
t.Id,
t.Value
};
return
new CustomClass
{
Results1 = results1,
Results2 = results2
};
}
*****
Session["Results"] = GetResults();
答案 0 :(得分:0)
只需在.ToList()
和result1
上使用result2
。
return
new CustomClass
{
Results1 = results1.ToList(),
Results2 = results2.ToList()
};