Entity framework EF 6代码首先从数据库模型生成错误
已安装VS 2015最新更新,所有软件包都是最新的。然后,我几乎每次都在从数据库中首先使用代码重新生成数据模型时遇到以下错误(我使用T4进行了一点自定义)。以前从未有过这种错误。有时,我可以通过重新启动VS 2015或重新启动我的工作站来解决此错误,但并不总是这样。任何人都有同样的问题。谢谢你的帮助Entity framework EF 6代码首先从数据库模型生成错误,entity-framework,t4,Entity Framework,T4,已安装VS 2015最新更新,所有软件包都是最新的。然后,我几乎每次都在从数据库中首先使用代码重新生成数据模型时遇到以下错误(我使用T4进行了一点自定义)。以前从未有过这种错误。有时,我可以通过重新启动VS 2015或重新启动我的工作站来解决此错误,但并不总是这样。任何人都有同样的问题。谢谢你的帮助 An error occurred generating the Code First model. The error occurred generating the contents of Db
An error occurred generating the Code First model. The error occurred generating the contents of DbCtx.cs.
System.InvalidOperationException: Compiling transformation: The type ‘DbModel’ exists in both ‘EntityFramework, Version=4.2.0.0, Colture=neutral, PublicKeyToken=b77a5c561934e089’ and 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
at Microsoft.Data.Entity.Design.CodeGeneration.CustomGenerator.ProcessTemplate()
at Microsoft.Data.Entity.Design.CodeGeneration.CustomGenerator.Generate(DbModel model, String codeNamespace, String contextClassName, String connectionStringName)
at Microsoft.Data.Entity.Design.CodeGeneration.CodeFirstModelGenerator.d__3.MoveNext()
=========这是我的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=301879
-->
<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>
<appSettings>
.......
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<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.WebPages" 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.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
<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>
<connectionStrings>
<add name="myDB" connectionString="data source=local DB;initial catalog=test;user id=user;password=pwd;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
.......
似乎您同时添加了Entity Framework V.6和V.4作为项目的参考。删除其中一个。似乎您同时添加了实体框架V.6和V.4作为项目的参考。移除其中一个。是的,这是我的第一个想法。但是我找不到任何V4 dll。另外,如果我删除了所有的NuGet软件包并重新安装了这些软件包,有时它会解决问题(但大多数情况下不会)。连接字符串和app.config/web.config中引用了哪个版本?是的,这是我的第一个想法。但是我找不到任何V4 dll。另外,如果我删除了所有的NuGet软件包并重新安装了这些软件包,有时它会解决问题(但大多数情况下不会)。在您的连接字符串和app.config/web.config中引用了哪个版本?有什么消息吗?我也有同样的问题…有什么消息吗?我也有同样的问题。。。