Efficient way to cache frequently used lists in entity framework 4.0

In a .Net c# application we are designing we have several tables with a small number of lookup values.  For example we have a table Payment which has FKs to table Status (Complete, Pending, Refunded) and table Type (Cash, CreditCard, BankTransfer).  

We are using Entitiframework 4.0 .  The table Status and Type have very few entries that rarely change so I don't want to keep querying the DB over and over again for their values.  What is the best way to cache the values so the entities can be smarter?
canuckconsultingAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ericpeckhamCommented:
The way I do this is to create my own list class in the same namespace as your entities, as in the following example, where the type I want to cache the list for is named ItemType.  I also like to throw in a couple of indexers.  The list itself is lazy-loaded, meaning it isn't fetched from the database until it's needed.

 
namespace MyDB
{
  public class ItemTypeList : List<ItemType>
  {
    private ItemTypeList()
    {
    }

    private ItemTypeList(List<ItemType> list)
      : base(list)
    {
    }

    private static List<ItemType> _ItemTypes;
    public static ItemTypeList ItemTypes
    {
      get
      {
        if (_ItemTypes == null)
        {
        	// No constructor argument - uses named connection string from app.config:
          using (MyEntityDB db = new MyEntityDB())
          {
            _ItemTypes = db.ItemTypes.ToList();
          }
        }
        return new ItemTypeList(_ItemTypes);
      }
    }

    public new ItemType this[int itemTypeID]
    {
      get
      {
        return Find(i => i.ItemTypeID == itemTypeID);
      }
    }

    public ItemType this[string typeName]
    {
      get
      {
        return Find(i => string.Compare(i.TypeName, typeName, true) == 0);
      }
    }
  }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cubaman_24Commented:
Hello:
Take a look at System.Web.Cache class.
http://msdn.microsoft.com/en-us/library/system.web.caching.cache.aspx

Here are some examples of caching at different levels
http://authors.aspalliance.com/aspxtreme/webapps/aspcachingfeatures.aspx

Best regards
0
canuckconsultingAuthor Commented:
Thank you and sorry for delay
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.