繁体   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