I am using VS 2013. I am trying to use SQL Server Compact with Entity Framework 6. Created database and .EDMX
model in VS 2012 and opened in VS 2013. I installed latest EF and EF SQL.CE from NuGet. When I try to run I am getting the following error
No connection string named 'SomeDbFile' could be found in the application config file.
app.config
:
<?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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="SomeDbFile"
connectionString="metadata=res://*/EDataModel.csdl|res://*/EDataModel.ssdl|res://*/EDataModel.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="data source=|DataDirectory|\dbfile.sdf""
providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
</configuration>
Generated DbContext
:
public partial class Entities : DbContext
{
public Entities() : base("name=SomeDbFile")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<category> category { get; set; }
public DbSet<item> item { get; set; }
public DbSet<order> order { get; set; }
public DbSet<order_line> order_line { get; set; }
}
You probably forgot to put the connection settings in your main application (the thing that is actually run) app.config.
app.config files in class library projects do nothing at runtime and are generally useless. (Some IDE features might need them though)