Entity Framework 插件问题 ASP.MVC 架构

Entity Framework issue with plugin ASP.MVC architecture

我正在实施那篇文章中描述的可插入 MVC 应用程序:http://blog.longle.net/2012/03/29/building-a-composite-mvc3-application-with-pluggable-areas/#plugin

基本上它有一个主要的 Web 应用程序 (ASP.MVC 4) 和一些子 Web 应用程序,这些应用程序使用一些 class 库作为它们的层 (DAL,BLL)。

我面临以下问题。我在 SubProject1.DataAccess class 库中定义了实体模型 (edmx)。然后我有 SubProject1.Web 项目,最后我有主要的 Web 项目。 SubProject1.Web 声明了以下构建后事件:

xcopy "$(ProjectDir)\Views" "$(TargetDir)\SubProject1\Views\" /s /i /y

它还将主 Web 应用程序 \Areas 目录设置为输出路径。

当我尝试从 DbContext 对象访问某些实体时,Entity Framework 抛出以下异常:

Unable to load the specified metadata resource.

堆栈跟踪:

at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource..ctor(String originalPath, String assemblyName, String resourceName, ICollection1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataCache.SplitPaths(String paths) at System.Data.Common.Utils.Memoizer2.<>c__DisplayClass2.<Evaluate>b__0() at System.Data.Common.Utils.Memoizer2.Result.GetValue() at 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)<br> 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.Initialize() at System.Data.Entity.Internal.Linq.InternalSet1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
at 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 16<br> 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.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass81.b__7(IAsyncResult _) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.b__33() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.b__49()

EF 似乎找不到 edmx 文件的位置。有谁知道我该如何解决这个问题?

如果每个模块都有自己的 EF 模型,则这些实体的每个连接字符串都需要位于主 Web 项目中,模块的所有视图都复制到该项目中。基于该错误,指向文件元数据的连接字符串似乎不在最终配置文件中。