當試圖使用的EntityFramework電動工具(0.9測試版)的Generate Views
功能,生成失敗,我得到以下錯誤在輸出窗口:EntityFramwork電動工具的錯誤而產生的觀點
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
,當電動工具試圖爲Identity模型生成視圖時,似乎會導致此問題。
這種情況只發生在試圖生成視圖。解決方案本身的構建和運行沒有任何錯誤。
爲了簡化和隔離這個問題,我創建了一個新的網站項目在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>
好像電動工具目前還不堅持使用6.0版本,沒有這個System.ComponentModel.DataAnnotations.Schema.IndexAttribute
類型的,因爲它在6.1版本只出臺,但它增加了到最新的Identity模型來限制唯一的UserName。
有什麼想法?
爲什麼不手動創建視圖? – trailmax
@trailmax你能詳細說明一下嗎? – Issac
只需手工創建視圖,而不是使用腳手架 – trailmax