VistaDB 5
Gibraltar VistaDB > Getting Started > Using VistaDB with Entity Framework > Using VistaDB with Entity Framework - Registering the Provider
Using VistaDB with Entity Framework - Registering the Provider

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.  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.  You will still need VistaDB installed locally to get the VistaDB Engine, but the Entity Framework provider will be installed 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.VistaDB5;
           provider connection string='data source=&quot;D:\Data\Gibraltar Analyst Repository\Index.vdb5&quot;'" 
         providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.VistaDB5" />
      <add invariant="System.Data.VistaDB5" name="VistaDB 5 Data Provider" 
           description="VistaDB 5 ADO.NET Provider for .Net 4" 
           type="VistaDB.Provider.VistaDBProviderFactory, VistaDB.5.NET40" />
    </DbProviderFactories>
  </system.data>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.VistaDB5" type="VistaDB.Entity.VistaDBProviderServices, VistaDB.5.Entity.6.NET40" />
    </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.VistaDB5;
           provider connection string='data source=&quot;D:\Data\Gibraltar Analyst Repository\Index.vdb5&quot;'" 
         providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.VistaDB5" />
      <add invariant="System.Data.VistaDB5" name="VistaDB 5 Data Provider" 
           description="VistaDB 5 ADO.NET Provider for .Net 4" 
           type="VistaDB.Provider.VistaDBProviderFactory, VistaDB.5.NET40" />
    </DbProviderFactories>
  </system.data>
</configuration>
See Also