• Webinars
  • Docs
  • Download
  • Blogs
  • Contact Us
Show / Hide Table of Contents
  • Getting Started with NCache
  • Setting up NCache Environment
  • Create Cache
  • NCache API Caching
  • ASP.NET Session State
  • ASP.NET Core Session
  • ASP.NET View State
  • ASP.NET Output Cache
  • NHibernate
  • Entity Framework Integration

Entity Framework Integration in NCache

NCache custom Entity Framework ADO.NET provider can be integrated in the application without any code change. Simply modify configuration files and specify NCache Entity Framework Caching Provider as second Level Cache provider.

Prerequisites

  1. Any Entity Framework application. The sample application for Entity Framework Caching from NCache sample applications can also be used from the following path: %NCHOME%/samples/dotnet/EntityFramework.

  2. Microsoft Visual Studio 2010 for Entity Framework 3.5 and 4.0 and Microsoft Visual Studio 2012 onwards for Entity Framework 6.0 and 6.1.

  3. Database Tool (e.g. MS SQL SERVER, ORACLE)

Important

This Getting Started section only caters to Entity Framework 6.1. For integration with EF 3.5, 4.0 and 6.0, refer to the detailed chapter on Entity Framework Integrations in Programmers' Guide.

Steps required to enable NCache as Second Level Cache Provider in Entity Framework application are as follows:

Reference Assembly

To utilize the Provider, include the following namespace in your application: Alachisoft.Integrations.EntityFramework.CachingProvider found in %NCHOME%/integration/MSEntityFramework.

Modify App.config or Web.config

App.config or Web.config which is generated on adding ADO.NET Entity Data Model in Entity Framework application, requires following changes:

Specify Provider Invariant Name

Entity Framework 6.1

Add an interceptor in <provider> section in either App.config or Web.config of your application:

<entityFramework>
    <providers>
        <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>

    <interceptors>
        <interceptor type="Alachisoft.NCache.Integrations.EntityFramework.Caching.EFCommandInterceptor, Alachisoft.Integrations.EntityFramework.CachingProvider"/>
    </interceptors>
</entityFramework>

Add Application ID to appSettings

The following information should be added in <appSettings> of App.config or Web.config.

Note

These settings are independent of Entity Framework version.

<appSettings>
    <add key="app-id" value="EFCachingDemo"/>
    <add key="logging-level" value="Debug"/>
</appSettings>

Modify efcaching.ncconf

efcaching.ncconf configuration contains cache and caching policy related information used by NCache Entity Framework caching provider. Some changes are required in efcaching.ncconf to run the Entity Framework Application with NCache. This config file is placed in %NCHOME%/config.

Below are the changes required in efcaching.ncconf.

<configuration>
    <app-config app-id="EFCachingDemo" mode="analysis|caching">

        <analysis-policy log-path="" analysis-time="1min" cache-enable-threshold="1" default-expiration-type="Sliding" default-expiration-time="180sec" dbsyncdependency="false"/>

        <cache-policy-configuration database="none|sqlserver|oracle" cache-id="mycache">
            <!--sql-query = "SELECT [Extent1].[CustomerID] AS [CustomerID],= @param_0"-->
            <query>
                <cache-query querytext="SELECT [Extent1].[OrderID] AS [OrderID], &lt; @param_0"/>
                <cache-policy vary-by-cache-param="param_0" expiration-type="Sliding" enabled="True" expiration-time="180sec" dbsyncdependency="False">
            </query>
        </cache-policy-configuration>

    </app-config>
</configuration>
Important

For details about each configuration member specified above, please refer to the detailed section EFCaching configuration file in Programmers' Guide.

Back to top Copyright © 2017 Alachisoft