Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I cache an IQueryable object?

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;
}

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.

like image 807
Nick Avatar asked Dec 14 '22 03:12

Nick


1 Answers

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

like image 84
Ali Ersöz Avatar answered Dec 26 '22 11:12

Ali Ersöz