簡體   English   中英

EF:找不到方法:'System.Data.Entity.Core.Metadata.Edm.EdmModel System.Data.Entity.Infrastructure.DbModel.get_StoreModel()'

[英]EF: Method not found: 'System.Data.Entity.Core.Metadata.Edm.EdmModel System.Data.Entity.Infrastructure.DbModel.get_StoreModel()'

我有一個共享的自定義“代碼優先”DbContext 對象的解決方案。

從今天開始,在嘗試以這種方式訪問​​實體后的一個項目中

 using(var cx = new MyContext())
 {
    var data = cx.Persons;
 }

我正在關注異常。

    {"Method not found: 'System.Data.Entity.Core.Metadata.Edm.EdmModel System.Data.Entity.Infrastructure.DbModel.get_StoreModel()'."}
        [System.MissingMethodException]: {"Method not found: 'System.Data.Entity.Core.Metadata.Edm.EdmModel System.Data.Entity.Infrastructure.DbModel.get_StoreModel()'."}
        Data: {System.Collections.ListDictionaryInternal}
        HelpLink: null
        HResult: -2146233069
        InnerException: null
        Message: "Method not found: 'System.Data.Entity.Core.Metadata.Edm.EdmModel System.Data.Entity.Infrastructure.DbModel.get_StoreModel()'."
        Source: "CodeFirstStoreFunctions"
        StackTrace: "   at CodeFirstStoreFunctions.FunctionsConvention.Apply(EntityContainer item, DbModel model)\r\n   
atSystem.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.ModelConventionDispatcher.Dispatch[T](T item)\r\n   
at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.ModelConventionDispatcher.VisitEdmEntityContainer(EntityContainer item)\r\n   
at System.Data.Entity.Edm.EdmModelVisitor.VisitCollection[T](IEnumerable`1 collection, Action`1 visitMethod)\r\n   at System.Data.Entity.Edm.EdmModelVisitor.VisitEntityContainers(IEnumerable`1 entityContainers)\r\n   at System.Data.Entity.Edm.EdmModelVisitor.VisitEdmModel(EdmModel item)\r\n   at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.ModelConventionDispatcher.VisitEdmModel(EdmModel item)\r\n   
at System.Data.Entity.ModelConfiguration.Configuration.ConventionsConfiguration.ModelConventionDispatcher.Dispatch()\r\n   at System.Data.Entity.ModelConfiguration.Configuration.Conven
    tionsConfiguration.ApplyStoreModel(DbModel model)\r\n   
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)\r\n   at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)\r\n   at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)\r\n   at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)\r\n   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()\r\n   at System.Data.Entity.Internal.InternalContext.Initialize()\r\n   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)\r\n   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()\r\n   at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()\r\n   at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()\r\n   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n   at ... }

這很奇怪,因為在其他項目中,自定義 Context 工作正常。

我試過的:

  • 清理和重建
  • 比較連接字符串

消息是什么意思?

任何幫助表示贊賞。

就我而言,此錯誤是由混合實體框架包引起的。 “項目 A”使用了 6.1.3 版的實體框架。 作為“項目 A”的測試項目的“項目 B”使用了 6.0.0 版。

當我的測試執行時,這正是上面顯示的錯誤消息。

兩個項目都升級到6.1.3后,錯誤消失了。

我遇到了同樣的問題,我得到了解決

  1. 從 GAC MSIL 中刪除 EntityFramework.dll
  2. 刷新數據模型(在刪除 entityframework.dll 之前它不允許我從 edmx 添加/刪除表)
  3. 使用命令 gacutil -i entityframework.dll 在 GAC 文件中添加 entityFramework.dll
  4. 清潔溶液
  5. 構建解決方案

PS:確保所有的entityframework.dll 版本都相同(項目-GAC 文件),並且app config 包含連接字符串

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM