Entity Framework 4 and caching of query results

后端 未结 3 1681
日久生厌
日久生厌 2020-12-14 07:24

Say I have a table or 2 that contains data that will never or rarely change, is there any point of trying to cache those data? Or will the EF context cache that data for me

3条回答
  •  一个人的身影
    2020-12-14 07:58

    you'll have to roll your own for any ef4 linq queries, as they are always resolved to sql, and thus will always hit the db. a simple cache for your couple tables probably wouldn't be hard to write.

    if you're going to be querying by id though, you can use the ObjectContext.GetObjectByKey method, and it will look in the object cache before querying the db.

提交回复
热议问题