2

我正在为我的 DAL 使用实体框架(使用 DBContext)。我们在关注点分离方面遵循的分层架构,为此目的,生成的实体类必须放在单独的类项目中。由于程序必须是可单元测试的,因此我使用存储库模式,因此我需要抽象我们从 EF 获得的 DbContext。这一切意味着实体类和上下文类不在我的 edmx 文件所在的同一个项目中。问题是当我移动文件时,我开始出现以下异常

未处理的异常:System.Data.MetadataException:无法加载指定的元数据资源。在
System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection 1 uriReg istry, MetadataArtifactAssemblyResolver resolver) at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateRes ourceLoader(String path, ExtensionCheck extensionCheck, String validExtension , 我在 System.Data.Common.Utils.Memoizer 2.Result.GetValue() 在 System.Data.Metadata.Edm.MetadataCache.SplitPaths(String paths) 处收集 1 uriRegistry ,Metad ataArtifactAssemblyResolver 解析器 。 Utils.Memoizer1 uriRegistry, Metada taArtifactAssemblyResolver resolver) at
System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource..ctor(Str ing originalPath, String assemblyName, String resourceName, ICollection

1 uriRegistry, MetadataArtifactAssemblyResolver resolver) at
System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, Extens ionCheck extensionCheck, String validExtension, ICollection


2.<>c__DisplayClass2.<Evaluate>b__0() at System.Data.Common.Utils.Memoizer
2.Evaluate(TArg arg) at
System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean ini tializeAllCollections) at
System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection( ) at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boole an isConnectionConstructor) at
System.Data.Objects.ObjectContext..ctor(EntityConnection connection)
at
System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConn ectionModel() at
System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFrom ConnectionModel() at
System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType (Type entityType) at
System.Data.Entity.Internal.Linq.InternalSet
1.Initialize() 在
System.Data.Entity.Internal.Linq.InternalSet 1.System.Linq.IQueryable.get_Provider() 在 System.Linq.Queryable.Where[TSource](IQueryable 1 谓词) 在 BusinessLayer.CustomerLocator .LocateCustomerByIdint id) 在 C:\Sandbox\BusinessLayer\CustomerLocator.cs:line 41 at ClientApp.Program.Main(String[] args) in C:\Sandbox\Program.cs:line 341.get_InternalContext()
at
System.Data.Entity.Infrastructure.DbQuery
1 source, Expression

谷歌搜索表明 csdl、ssdsl 等的路径可能有问题,但我不确定这里有什么问题。以下是我的连接字符串的设置方式

<add name="DBConnection" 
   connectionString="metadata=res://*/MyDataModel.csdl|res://*/MyDataModel.ssdl|res://*/MyDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=Customers;persist security info=True;user id=user;password=password;multipleactiveresultsets=True;App=EntityFramework&quot;" 
providerName="System.Data.EntityClient" />
4

0 回答 0