【发布时间】:2015-02-16 16:12:26
【问题描述】:
我正在实现那篇文章中描述的可插拔 MVC 应用程序:http://blog.longle.net/2012/03/29/building-a-composite-mvc3-application-with-pluggable-areas/#plugin
基本上它有一个主 Web 应用程序 (ASP.MVC 4) 和一些使用一些类库作为其层 (DAL、BLL) 的子 Web 应用程序。
我面临以下问题。我在 SubProject1.DataAccess 类库中定义了实体模型(edmx)。然后我有 SubProject1.Web 项目,最后我有主 Web 项目。 SubProject1.Web 声明了以下构建后事件:
xcopy "$(ProjectDir)\Views" "$(TargetDir)\SubProject1\Views\" /s /i /y
它还将主 Web 应用程序 \Areas 目录设置为输出路径。
当我尝试从 DbContext 对象访问某个实体时,实体框架会抛出以下异常:
无法加载指定的元数据资源。
堆栈跟踪:
在 System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(字符串 程序集名称、字符串资源名称、ICollection
1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource..ctor(String originalPath, String assemblyName, String resourceName, ICollection1 uriRegistry,MetadataArtifactAssemblyResolver 解析器)在 System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(字符串 路径,ExtensionCheck extensionCheck,字符串validExtension, ICollection1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection1 uriRegistry,MetadataArtifactAssemblyResolver 解析器)在 System.Data.Metadata.Edm.MetadataCache.SplitPaths(字符串路径)在 System.Data.Common.Utils.Memoizer2.<>c__DisplayClass2.<Evaluate>b__0() at System.Data.Common.Utils.Memoizer2.Result.GetValue() 在 System.Data.Common.Utils.Memoizer2.Evaluate(TArg arg) at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections) at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection() at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor) at System.Data.Objects.ObjectContext..ctor(EntityConnection connection)1.Initialize() 在 System.Data.Entity.Internal.Linq.InternalSet
at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel() at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel() at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery1.System.Collections.Generic.IEnumerable.GetEnumerator() 在 System.Collections.Generic.List1..ctor(IEnumerable1 集合)
在 System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at SubProject1.DataAccess.DataSources.OracleDb.OracleDb.get_Administrators() in c:\somepath\SubProject1.DataAccess\DataSources\OracleDb\OracleDb.cs:line 60 at SubProject1.Web.Controllers.SubTestController.Index() in d:\somepath\SubProject1.Web\Controllers\SubTestController.cs:line 162 参数)在 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass81.b__7(IAsyncResult _) 在 System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
在 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.c__DisplayClass37.c__DisplayClass39.b__33() 在 System.Web.Mvc.Async.AsyncControllerActionInvoker.c__DisplayClass4f.b__49()
似乎 EF 找不到 edmx 文件的位置。有谁知道我该如何解决这个问题?
【问题讨论】:
-
将正确的实体框架连接字符串放入您的 web.config。
标签: c# asp.net-mvc entity-framework asp.net-mvc-4