Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Entity Framework 4 and caching of query results

// The EF context will cache "per instance". That is, each instance of the 
// DbContext keeps it's own independent cache of objects. You can store the resulting 
// list of objects in a static list and query it all you like without returning to the 
// database. To be safe, make sure you abandon the DbContext after you execute the query.

var dbContext = new YourDbContext();
StaticData.CachedListOfThings = dbContext.ListOfThings.ToList();

// You can later use LINQ to query the static list.

var widgets = StaticData.CachedListOfThing.Where(thing => thing.Widget == "Foo");
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Entity #Framework #caching #query #results
ADD COMMENT
Topic
Name
7+2 =