如何告诉Entity Framework首先在代码中使用SQL Server Compact?

时间:2014-04-15 18:58:40

标签: c# entity-framework sql-server-ce

如何更改app.config或Migration Configuration.cs文件,以便Entity Framework使用本地SDF文件而不是本地SQL Server实例?我使用的是EF 6.1。

由于

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory,  EntityFramework" />
<providers>
  <provider invariantName="System.Data.SqlClient"   type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>

1 个答案:

答案 0 :(得分:1)

您应该只能在数据库的连接字符串中指定ProviderName。

<connectionStrings>
<add name="DataModelContext"
     providerName="System.Data.SqlServerCe.4.0"
     connectionString="Data Source=location\cfdb.sdf"/>