我如何缓存一个IQueryable对象? [英] How do I cache an IQueryable object?

查看:524
本文介绍了我如何缓存一个IQueryable对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种方法,在UserStatus'表返回一个LINQ到SQL查询中的所有行:

I've got this method that returns a Linq-to-SQL query for all the rows in a 'UserStatus' table:

public IQueryable<BLL.Entity.UserStatus> GetAll()
{
    var query = from e in _SelectDataContext.UserStatus
                select new BLL.Entity.UserStatus
                {
    	            UserStatusId = e.UserStatusId,
    	            Enum = e.Enum,
    	            Name = e.Name
                };

    return query;
}

这只是将几乎没有改变,因此我想缓存结果一看表。我可以将其转换为列表与LT;&GT; 和,但我preFER在类的其他方法取决于返回一个IQueryable对象缓存。任何人都可以帮忙吗?谢谢你。

It's just a look-up table that will hardly ever change so I'd like to cache the results. I can convert it to a List<> and cache that, but I'd prefer to return an IQueryable object as other methods in the class depend on that. Can anyone help? Thanks.

推荐答案

query.ToList()。AsQueryable已()成为你的解决方案?不是最好的肯定。

could query.ToList().AsQueryable() be a solution for you? not the best one sure.

这篇关于我如何缓存一个IQueryable对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆