实体框架defaultconnectionfactory

时间:2013-01-22 11:19:47

标签: asp.net entity-framework entity-framework-4.3

我最近使用实体框架4.3创建了一个新的Web项目。我使用数据库优先设计。

实体框架将此部分添加到我的web.config中,该部分提供了一些信息性错误消息。我已经在某处读过这段代码与代码第一次设计有关 - 我是否需要它 - 我只是删除它吗?

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

感谢。

3 个答案:

答案 0 :(得分:22)

这可能非常相关(强调我的):

  

配置部分允许您指定Code First应该用于定位要用于上下文的数据库的默认连接工厂。 默认连接工厂仅在未将连接字符串添加到上下文的配置文件中时使用

请参阅MSDN上的Entity Framework Config File Settings

答案 1 :(得分:2)

如果你没有使用CodeFirst,我不是100%确定是否重要(尝试删除它并查看它是否运行正常)。但是,如果您使用CodeFirst并使用SQLCE 4.0作为主数据库,那么您需要保留它。请参阅docs

  

如果未设置默认连接工厂,Code First将使用指向。\ SQLEXPRESS的SqlConnectionFactory。 SqlConnectionFactory还有一个构造函数,允许您覆盖连接字符串的一部分。如果要使用。\ SQLEXPRESS以外的SQL Server实例,可以使用此构造函数来设置服务器。

答案 2 :(得分:0)

您会收到这些警告消息,因为Web.config中缺少entityFramework的section元素定义。它看起来像这样:(注意:下面是EF5.0)

<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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />