Entity Framework defaultconnectionfactory

那年仲夏 提交于 2020-01-03 15:29:26

问题


I've recently created a new web project using entity framework 4.3. I'm using database first design.

Entity Framework added this section to my web.config, which is giving some informational error messages. I've read somewhere that this code relates to code first design - do I need it - do I just remove it?

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

Thanks.


回答1:


I am not 100% sure if it matters if you aren't using CodeFirst (try removing it and see if it runs ok). However, if you are using CodeFirst and using SQLCE 4.0 as your main database then you need to keep it. See the docs:

If you don’t set a default connection factory, Code First uses the SqlConnectionFactory, pointing to .\SQLEXPRESS. SqlConnectionFactory also has a constructor that allows you to override parts of the connection string. If you want to use a SQL Server instance other than .\SQLEXPRESS you can use this constructor to set the server.




回答2:


This may be very relevant (emphasis mine):

The configuration section allows you to specify a default connection factory that Code First should use to locate a database to use for a context. The default connection factory is only used when no connection string has been added to the configuration file for a context.

See Entity Framework Config File Settings on MSDN.




回答3:


You get those warning messages because the section element definition for entityFramework is missing in Web.config. It looks something like this: (note: the below is for 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" />


来源:https://stackoverflow.com/questions/14457375/entity-framework-defaultconnectionfactory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!