【发布时间】:2016-01-15 11:18:35
【问题描述】:
当尝试使用 EntityFramework Power Tools (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,当电动工具尝试为身份模型生成视图时,似乎是什么导致了这个问题。
只有在试图生成视图时才会发生这种情况。解决方案本身构建和运行没有任何错误。
为了简化和隔离这个问题,我在 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>
好像Power tools坚持使用6.0版本还没有System.ComponentModel.DataAnnotations.Schema.IndexAttribute类型,因为它只在6.1版本中引入,但它被添加到最新的Identity模型中以限制唯一的UserName。
有什么想法吗?
【问题讨论】:
-
为什么不手动创建视图?
-
@trailmax 你能详细说明一下吗?
-
只手动创建视图,不使用脚手架
-
@trailmax,我不确定我们在谈论同一件事。我的问题是为 EntityFramwork 生成预编译视图以提高查询性能,尤其是在启动时。
-
没错,我们在谈论不同的事情。为混乱道歉。
标签: entity-framework visual-studio asp.net-identity ef-power-tools