实体框架 – 具有SQL Server Compact 4.0的实体框架6

我(仍然)试图遵循一个在线视频教程,介绍如何使用实体框架与代码优先的方法.就我的EDM验证是否正确,现在是实际构建数据库的时候了.教师使用sql Server,显然当第一个查询命令(ToList())针对DbContext对象时自动创建数据库.

由于我计划在将来的应用程序中使用基于sql Server Compact文件数据库,所以我尝试使用sql Server Compact 4.0重现教程的示例.我安装了NuGet软件包“EntityFramework.sqlServerCompact”和“Micrososft sql Server Compact Edition”.显然这会导致在app.config中提供一个新的提供者条目:

<providers>
  <provider invariantName="System.Data.sqlServerCe.4.0" type="System.Data.Entity.sqlServerCompact.sqlCeProviderServices,EntityFramework.sqlServerCompact" />
</providers>

但是当我运行第一个查询命令时,我收到错误消息

Migrations is enabled for context ‘DataModelContext’ but the database does not exist or contains no mapped tables. Use Migrations to create the database and its tables,for example by running the ‘Update-Database’ command from the Package Manager Console.

当我运行更新数据库我收到消息:

No pending explicit migrations.
Applying automatic migration: 201310311356014_AutomaticMigration.
Running Seed method.

并且不创建数据库,至少程序仍然退出上述错误消息.

EF不会自动创建sql Server CE数据库吗?如果是这样,如何连接手动创建的数据库与我的应用程序?

解决方法

通过在< configuration> -tag的末尾手动添加一个连接字符串到app.config文件可以解决这个问题:
<connectionStrings>
    <add name="DataModelContext"
         providerName="System.Data.sqlServerCe.4.0"
         connectionString="Data Source=C:\Users\sblxxx\Documents\Visual Studio 2012\Projects\Pluralsight\EF5\CodeFirst\db\cfdb.sdf"/>
  </connectionStrings>

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...