我有一个这样定义的权限列表:
private List<PermissionItem> permissionItems;
private ReadOnlyCollection<PermissionItem> permissionItemsReadOnly;
该列表是通过后台线程从 Web 服务中检索的。只读版本由 List 版本填充。
我将此列表公开给我的(相当大的)应用程序的其余部分,如下所示:
public IQueryable<PermissionItem> PermissionItems
{
get
{
// Make sure that the permissions have returned.
// If they have not then we need to wait for that to happen.
if (!doneLoadingPermissions.WaitOne(10000))
throw new ApplicationException("Could not load permissions");
return permissionItemsReadOnly.AsQueryable();
}
}
这一切都很好。用户可以请求权限并在加载后获取它们。
但是,如果我在构造函数中有这样的代码(在不同的类中):
ThisClassInstanceOfThePermisssions = SecurityStuff.PermissionItems;
然后我相当确定这将阻止直到权限返回。但在实际使用权限之前,它不需要阻塞。
我读过 IQueryable 是“延迟加载”。(我在我的实体框架代码中使用了这个功能。)
有没有办法可以更改它以允许随时引用我的 IQueryable,并且仅在实际使用数据时才阻止?
注意:这是一个“值得拥有”的功能。实际上加载权限不会花费太长时间。所以如果这是一个“自己动手”查询/表达式的东西,那么我可能会通过。但我很好奇如何让它发挥作用。