EF数据库配置

1 <?xml version="1.0" encoding="utf-8"?>
 2 <configuration>
 3     <configSections>
 4         <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
 5         <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
 6     </configSections>
 7     <entityFramework>
 8         <providers>
 9             <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
10         </providers>
11     </entityFramework>
12     <connectionStrings>
13         <add name="BlogContext"
14               providerName="System.Data.SqlClient"
15               connectionString="Server=xxx;Database=xxx;Integrated Security=False;User ID=sa;Password=xxx;"/>
16     </connectionStrings>
17 </configuration>

配置的数据库连接字符串配置项的name应该与你的Context类型的名称一致,例如本例中就应该配置为BlogContext

原文地址:https://www.cnblogs.com/ymh2013/p/3565349.html