我正在实施该文章中描述的可插入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声明了以下postbuild事件:
xcopy "$(ProjectDir)\Views" "$(TargetDir)\SubProject1\Views\" /s /i /y
它还将主Web应用程序\Areas
目录设置为输出路径。
当我尝试从DbContext对象访问某个实体时,Entity Framework会抛出以下异常:
无法加载指定的元数据资源。
堆栈跟踪:
在 System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(字符串 assemblyName,String resourceName,ICollection
1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource..ctor(String originalPath, String assemblyName, String resourceName, ICollection
1 uriRegistry,MetadataArtifactAssemblyResolver resolver)at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(字符串 path,ExtensionCheck extensionCheck,String validExtension, ICollection的1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection
1 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.Memoizer
2.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)
1.Initialize()at 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.DbQuery
1.System.Collections.Generic.IEnumerable.GetEnumerator() 在System.Collections.Generic.List1..ctor(IEnumerable
1集合)
在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
2个参数)at at 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__DisplayClass8
1.b__7(IAsyncResult) _)at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
在 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult的 asyncResult)at System.Web.Mvc.Async.AsyncControllerActionInvoker&LT;&GT; c__DisplayClass37&LT;&GT; c__DisplayClass39.b__33() 在 System.Web.Mvc.Async.AsyncControllerActionInvoker&LT;&GT; c__DisplayClass4f.b__49()
似乎EF无法找到edmx文件的位置。有谁知道如何解决这个问题?
答案 0 :(得分:1)
如果每个模块都有自己的EF模型,那么这些实体的每个连接字符串都需要在主Web项目中,其中所有模块的视图都被复制到其中。基于该错误,似乎指向文件元数据的连接字符串不在最终配置文件中。