我有一个使用Entity Framework的类库项目,它运行良好,直到我将模型移到一个单独的类库类型项目。
在我将模型移到一个名为Model的单独的类库项目之后,我将app / web.config中的连接字符串更改为如下所示:
<add name="GlobalizationEntities"
connectionString="metadata=res://Model.dll/Models.ResourceGlobalizationModel.csdl|
res://Model.dll/Models.ResourceGlobalizationModel.ssdl|
res://Model.dll/Models.ResourceGlobalizationModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=MyComputer\sqlexpress;
Initial Catalog=DaDatabase;
Integrated Security=true;
MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
(我上面的代码段中包含换行符只是为了便于阅读。我的代码没有这些换行符。)
现在,我的解决方案结构如下所示:
但是,我在运行时得到FileNotFound
异常,内容如下:
System.IO.FileNotFoundException was unhandled by user code
HResult=-2147024894
Message=Unable to resolve assembly 'Model.dll'.
Source=System.Data.Entity
StackTrace:
at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.ResolveAssemblyName(String assemblyName, MetadataArtifactAssemblyResolver resolver)
at System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String 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.Memoizer`2.<>c__DisplayClass2.<Evaluate>b__0()
at System.Data.Common.Utils.Memoizer`2.Result.GetValue()
at System.Data.Common.Utils.Memoizer`2.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(String connectionString, String defaultContainerName)
at Resources.BaseServices.Globalization.Models.ResourceGlobalizationEntities..ctor() in C:\SVN\Model\ResourceGlobalizationEntities.cs:line 7
at Resources.BaseServices.Globalization.Models.Culture.IsValidCulture(String shortName) in C:\SVN\Model\Culture.cs:line 24
at Resources.BaseServices.Globalization.EntityFrameworkStringResourceLoader.set_CultureName(String value) in C:\SVN\BusinessObjects\EntityFrameworkStringResourceLoader.cs:line 129
at Resources.BaseServices.Globalization.EntityFrameworkStringResourceLoader..ctor(String cultureName, IDataSource dataSource) in C:\SVN\BusinessObjects\EntityFrameworkStringResourceLoader.cs:line 19
InnerException:
我尝试了2个客户端的场景,即控制台应用程序和MVC应用程序。
虽然控制台应用程序甚至没有将BusinessObjects.dll
及其引用的dll,即Model.dll
复制到控制台应用程序的bin
目录,但MVC应用程序确实如此。然而,他们似乎都没有找到Model.dll
集会,并提出上述FileNotFoundException
。
答案 0 :(得分:1)
我认为问题来自EF ConStr。通常,当您要使用嵌入式资源时,应将Metadata
设置为以下内容:
Metadata=res://<assemblyFullName>/<resourceName>.
您还可以使用*
通配符代替<assemblyFullName>
。它导致在运行时搜索文件的以下位置:
更多信息是here
答案 1 :(得分:0)
我已将function __construct($persons_name = null) {
if ($persons_name !== null)
$this->name = $persons_name;
else {
// your code when argumet is omited
}
}
$hasee= new person();
EF模型移至其自己的文件夹(Ecom.edfx
)
如果生成的EF连接字符串将其元数据设置如下,则检入Ecom
/(Web.config
)
app.config
(目录结构使用<add name="EcomEntities" connectionString="metadata=res://*/Ecom.Ecom.csdl|res://*/Ecom.Ecom.ssdl|res://*/Ecom.Ecom.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string="data source=****"" providerName="System.Data.EntityClient" />
(点)而非.
(斜杠)完成,如下面的 res:// /Ecom.Ecom.csdl < / strong> (来自 res:// /Ecom.csdl ,而不在其自己的文件夹中)。