如何告诉实体框架首先在代码中使用SQL Server Compact
本文关键字:SQL Compact Server 代码 实体 何告诉 框架 | 更新日期: 2023-09-27 17:58:40
如何更改app.config或迁移配置.cs文件,使实体框架使用本地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>
您应该能够在数据库的连接字符串中指定ProviderName。
<connectionStrings>
<add name="DataModelContext"
providerName="System.Data.SqlServerCe.4.0"
connectionString="Data Source=location'cfdb.sdf"/>