ASP.NET MVC 5教程和LocalDB简介

时间:2014-02-13 21:38:21

标签: asp.net asp.net-mvc entity-framework visual-studio-2013 localdb

我正在经历this tutorial,我坚持第5步 - 创建连接字符串并使用SQL Server LocalDB。我得到的错误是:

There was an error running the selected code generator:

'Unable to retrieve metadata for 'MvcMovie.Models.Movie'. Unable to find the requested .Net Framework Data Provider. It may not be installed.'

我在互联网上搜索了几天的答案。我尝试了很多解决方案,但都没有。我检查并重新检查了代码,我在Windows 7 64位PC上安装了Visual Studio Express 2013 for Web和更新1。任何人都可以帮我解决这个问题,使用LocalDB而不是其他数据库产品吗?

这是web.config:

    <?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<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>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MvcMovie-20140207025827.mdf;Initial Catalog=aspnet-MvcMovie-20140207025827;Integrated Security=True"
      providerName="System.Data.SqlClient" />
    <add name="MovieDBContext"
      connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Movie.mdf;Initial Catalog=Movies;Integrated Security=True"
      providerName="System.Data.SqlClient"
    />

  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <authentication mode="None" />
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <system.webServer>
    <modules>
      <remove name="FormsAuthenticationModule" />
    </modules>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

我已经在ASP.NET论坛上回答了一些问题并发布了截图,请仔细阅读 - Here

2 个答案:

答案 0 :(得分:1)

请修改连接字符串,如下所示:

<add name="MovieDbContext" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />

您可以查看以下文章以获得进一步的参考:

http://www.c-sharpcorner.com/UploadFile/4b0136/working-with-model-class-and-connection-string-in-mvc-5/

请查看应用程序的事件查看器详细信息。如果LocalDb已损坏,请运行以下命令:

SqlLocalDB Create C

答案 1 :(得分:0)

抱歉,这是一台计算机的问题。我能够在另一台计算机上做同样的事情。