EntityFramwork Power Tools在生成视图时出现错误

 2023-02-15    323  

问题描述

在尝试使用EntityFramework电动工具(0.9 beta)的Generate Views功能时,生成失败,我在输出窗口中获得以下错误:

System.Reflection.TargetInvocationException: 
Exception has been thrown by    the target of an invocation. --->
System.TypeLoadException: Could not load type 
'System.ComponentModel.DataAnnotations.Schema.IndexAttribute' from assembly 
'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at MyProject.Entities.Models.MyDbContext.OnModelCreating(DbModelBuilder modelBuilder)

我的上下文从IdentityDbContext继承,当电动工具尝试为身份模型生成视图时似乎导致此问题.

EntityFramwork Power Tools在生成视图时出现错误

这只是尝试生成视图的Wen.解决方案本身在没有任何错误的情况下构建和运行.

为了简化和隔离此问题,我在VS 2013中创建了一个新的网站项目,具有身份和实体框架6.0,生成工作正常.将包更新为Identity 2.2.1和EntityFrameWork 6.1.3导致错误,生成失败.

我已经检查了项目引用,看起来它看起来像正确的EntityFramework版本.

我的.csproj引用:

<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer">
  <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.Core">
  <HintPath>..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Identity.EntityFramework">
  <HintPath>..\packages\Microsoft.AspNet.Identity.EntityFramework.2.2.1\lib\net45\Microsoft.AspNet.Identity.EntityFramework.dll</HintPath>
</Reference>

似乎电动工具坚持使用没有System.ComponentModel.DataAnnotations.Schema.IndexAttribute类型的6.0版本,因为它只在6.1版本中引入,但它被添加到最新的身份模型中以限制唯一的用户名.

任何想法?

推荐答案

关闭电源工具使用的entityframework的Visual Studio IDE版本,而不是来自项目的引用.在我的情况下,它是6.0.2.安装 Visual Studio 2013更新5(2013.5)RTM 我的机器解决了这个问题,现在使用了最新的EntityFramework 6.1.3.

以上所述是小编给大家介绍的EntityFramwork Power Tools在生成视图时出现错误,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持!

原文链接:https://77isp.com/post/33750.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。