How do you automatically generate SDF in a Code First approach

I created POCO and context and added EF to my project from NuGet (v4.3.1). App.config looks a little new to me compared to what I'm used to. There is this section here:

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
  <parameters>
    <!--<parameter value="Data Source=|DataDirectory|Test.sdf; Integrated Security=True; MultipleActiveResultSets=True" />-->
  </parameters>
</defaultConnectionFactory>

      

I have commented out "parameter" and will add the connection string snippet instead below the tag at the top:

<connectionStrings>
  <add name="CodeFirstExampleContext" connectionString="Data Source=|DataDirectory|Test.sdf;Initial Catalog=CodeFirstExample;integrated security=True" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>

      

Previously, with such a connection string, the SQL CE database was automatically generated. however, this is not currently being done. Instead, I am getting the following exception:

"There was an error getting the provider information from the database. This could be caused by using the Entity Framework using the wrong connection string. Check internal exceptions for details and make sure the connection string is correct."

Inner Exception:

"The provider did not return the ProviderManifestToken string."

Here are my POCO and Context types:

class Person
{
    [Key]
    public int Id { get; set; }
    public string FName { get; set; }
    public string LName { get; set; }
    public int Age { get; set; }
}


class Context:DbContext
{
    public DbSet<Person> People { get; set; }
}

      

Did I miss something?

Thanks in advance!

+3


source to share


1 answer


Change your connection string to:

<connectionStrings> 
  <add name="Context" connectionString="Data Source=|DataDirectory|\Test.sdf"
    providerName="System.Data.SqlServerCe.4.0" /> 
</connectionStrings>

      



And change the default factory connection:

<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="System.Data.SqlServerCe.4.0" />
  </parameters>
</defaultConnectionFactory>

      

0


source







All Articles