VistaDB 6
VistaDB / Getting Started / Using VistaDB with Entity Framework / Using VistaDB with Entity Framework - Registering the Provider
In This Topic
    Using VistaDB with Entity Framework - Registering the Provider
    In This Topic

    Files Required for VistaDB

    You will need to include both the VistaDB Engine and the appropriate VistaDB Entity Framework Provider with your application.  See Deploying VistaDB with your Application for the specific files and locations.

    The simplest way to accomplish this is to use NuGet and select the appropriate provider. 

    Just search for VistaDB in NuGet.  During installation, VistaDB adds NuGet packages for all of its assemblies which can be found using the VistaDB 6 package source in VIsual Studio.  When you add the provider from NuGet it will ensure a compatible version of Entity Framework is selected and update the app.config file for you.

    Registering the VistaDB Entity Framework Provider

    In order to distribute your application built with the Entity Framework you need to register the VistaDB EF provider in the application configuration file (app.config/web.config) and ship the correct Entity Framework provider in the same place as the VistaDB engine.  Without this, deploying your EF powered application will result in an error on the target machine:

    The specified store provider cannot be found in the configuration, or is not valid.

    This is because the Entity Framework only loads from provider factories.  Even if you hard code the assembly reference in your app, on the target runtime machine the Entity Framework has to be able to find the factory dynamically.  See the provider factories page for more information.

    Example App.Config for Entity Framework

    The necessary configuration is different for Entity Framework 4.x through 5.x and Entity Framework 6.x and later.  As of Entity Framework version 6.0 a new provider model was introduced which requires a different assembly and slightly different configuration.  Note that in both cases the Database Provider Factory for ADO.NET also has to be registered.

    App.Config or Web.Config File
    Copy Code
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <section name="entityFramework" 
                 type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, 
                   Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                 requirePermission="false" />
      </configSections>
      <connectionStrings>
        <add name="Entities" 
             connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.VistaDB6;
               provider connection string='data source=&quot;D:\Data\Gibraltar Analyst Repository\Index.vdb6&quot;'" 
             providerName="System.Data.EntityClient" />
      </connectionStrings>
      <system.data>
        <DbProviderFactories>
          <remove invariant="System.Data.VistaDB6" />
          <add invariant="System.Data.VistaDB6" name="VistaDB 6 Data Provider" 
               description="VistaDB 6 ADO.NET Provider for .Net Framework" 
               type="VistaDB.Provider.VistaDBProviderFactory, VistaDB.6" />
        </DbProviderFactories>
      </system.data>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0" />
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.VistaDB6" 
    type="VistaDB.Entity.VistaDBProviderServices, VistaDB.6.Entity.6" />
        </providers>
      </entityFramework>
    </configuration>
    
    App.Config or Web.Config File
    Copy Code
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <connectionStrings>
        <add name="Entities" 
             connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.VistaDB6;
               provider connection string='data source=&quot;D:\Data\Gibraltar Analyst Repository\Index.vdb6&quot;'" 
             providerName="System.Data.EntityClient" />
      </connectionStrings>
      <system.data>
        <DbProviderFactories>
          <remove invariant="System.Data.VistaDB6" />
          <add invariant="System.Data.VistaDB6" name="VistaDB 6 Data Provider" 
               description="VistaDB 6 ADO.NET Provider for .Net Framework" 
               type="VistaDB.Provider.VistaDBProviderFactory, VistaDB.6" />
        </DbProviderFactories>
      </system.data>
    </configuration>
    
    See Also