views:

13

answers:

1

Is this possible to populate some constant small tables as cache for DataContext without using database?

For example, I have 10 Roles rows, and wonna quick (without database hit) access to them when doing big select?

A: 

If you cache the result of the first database hit subsequent hits will be prevented and will be called from cache.

var rolesList = (List<Role>)Cache["cachedroles"];
        if (rolesList == null)
        {
            using (var tDC= new theDataContext())
            {
                rolesList = siteroles.allrolesItems(tDC).OrderBy(c => c.listOrder).ToList();
                Cache.Insert("cachedroles", rolesList);
            }
        }
mark123