I have a simple console application setup and I am trying to get code-first Entity working properly. I've done the basic examples and have set up my classes and context. Once I run my application the database is auto generated and placed in my bin/Debug
directory. That's great so at least something works. But now I want to add a SQL Server Compact 4.0 database file (.sdf
) to the project and use that instead of the autogenerated database. From what I've read I just need to add a connection string with a name that matches the derived DbContext
class.
Below is my app.config
:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="StudentContext"
connectionString="Data Source=Database1.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.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>
</entityFramework>
</configuration>
And this is the error I am receiving when it tries to use the initialize the context.
The inner exception says
Configuration system failed to initialize
I've tried specifying the context directly though the constructor, and still no luck. Hopefully, I am just overlooking something.
(Side note, I grabbed EntityFramework from Nuget and it should be 5.0, yet the appconfig says 4.4? The autogeneration works great so I figured they didnt have anything to do with each other.)
4.4
- nothing wrong here (just confusing numbering schemes....) EF 5.0 will be5.0
on a .NET 4.5 project. – marc_s