none
When EF6 cache data RRS feed

  • Question

  • EF cache data by defult or we need provide some hint

    please provide a code which show EF getting data from cache.

    Monday, October 9, 2017 10:22 PM

Answers

  • Hi,

    EF entities are cached within corresponding DbSet,  caching is performed by DbContext on the entity level. You can use AsNoTracking method  which returns a new query where the entities returned will not be cached in the DbContext or ObjectContext.

    So you can query with no cache  as :Set<T>().AsNoTracking()

    Such as:

    from s in cont.Set<T>().AsNoTracking() select s;

    Best Regards,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Bob Ding Wednesday, October 18, 2017 12:04 PM
    • Marked as answer by Sudip_inn Wednesday, November 1, 2017 8:53 AM
    Tuesday, October 10, 2017 7:10 AM

All replies

  • Hi,

    EF entities are cached within corresponding DbSet,  caching is performed by DbContext on the entity level. You can use AsNoTracking method  which returns a new query where the entities returned will not be cached in the DbContext or ObjectContext.

    So you can query with no cache  as :Set<T>().AsNoTracking()

    Such as:

    from s in cont.Set<T>().AsNoTracking() select s;

    Best Regards,

    Bob


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Bob Ding Wednesday, October 18, 2017 12:04 PM
    • Marked as answer by Sudip_inn Wednesday, November 1, 2017 8:53 AM
    Tuesday, October 10, 2017 7:10 AM
  • EF5/6 always cache data when we fetch data by EF?

    or is there any option which i need to turn on to make the data cached?

    Wednesday, November 1, 2017 8:54 AM