我已将 Entity Framework 4 模型移至类库。元文件构建到 \bin\Debug
我用来在类库中定位元文件的连接字符串是什么?我努力了:
<add name="Models.DataModelConnectionString"
connectionString="metadata=res://MyClassLibrary, 1.0.0.0, neutral,
null/bin/Debug/Models.DataModel.csdl|res://MyClassLibrary, 1.0.0.0, neutral,
null/bin/Debug/Models.DataModel.ssdl|res://MyClassLibrary, 1.0.0.0, neutral,
null/bin/Debug/Models.DataModel.msl;provider=Devart.Data.Oracle;
....">
我仍然收到错误“指定的元数据路径无效”。
我需要将元文件移动到类库根目录吗?
Edit我尝试过使用res://*/Models.DataModel.csdl
等等,但收到错误“无法加载指定的元数据资源。”反而
当 EF 模型位于另一个项目使用的单独/项目(MyCompany.MyApp.Infra)中时,您需要在 app.config 或 web.config 中正确配置连接字符串
看这个例子:
MyContext.cs在 MyCompany.MyApp.Infra 项目中。
namespace MyCompany.MyApp.Domain
{
using System.Data.Objects;
/// <summary>
/// The MyContext
/// </summary>
public partial class MyContext : ObjectContext, IUnitOfWork
{
/// <summary>
/// The ConnectionString
/// </summary>
public const string ConnectionString = "name=MyContext";
/// <summary>
/// The ContainerName
/// </summary>
public const string ContainerName = "MyContext";
/// <summary>
/// Initializes a new instance of the <see cref="MyContext"/> class.
/// </summary>
public MyContext()
: base(ConnectionString, ContainerName)
{
this.ContextOptions.LazyLoadingEnabled = true;
}
}
}
网络配置在 Silverlight Web 项目中
<add name="MyContext"
connectionString="metadata=res://MyCompany.MyApp.Infra/DataModel.MyContext.csdl|
res://MyCompany.MyApp.Infra/DataModel.MyContext.ssdl|
res://MyCompany.MyApp.Infra/DataModel.MyContext.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=localhost\DB_01;Initial Catalog=MyDB;Persist Security Info=True;User ID=usr;Password=pwd;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient"
/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)