EF4和连接字符串 [英] EF4 and Connection String
问题描述
我有一个3层项目。
1)Project.Data(EDMX文件)
2)Project.Model br>
3)Project.Console(Console app)
我已将连接字符串添加到 Project.Console
。
<?xml version =1.0encoding =utf-8?&
< configuration>
< connectionStrings>
< add name =ProjectEntitiesconnectionString =metadata = res://*/Project.csdl | res://*/Project.ssdl | res://*/Project.msl; provider = System .Data.SqlClient;提供程序连接字符串=& quot;数据源= PC\SQLEXPRESS;初始目录=项目;集成安全性= True; MultipleActiveResultSets = True& providerName =System.Data.EntityClient/>
< / connectionStrings>
< / configuration>
Project.Model
EntityObject
T4模板在VS2010。它生成一个 ObjectContext
类,具有此构造函数:
public ProjectEntities ):base(name = ProjectEntities,ProjectEntities)
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
我只是试图实例化 code>:
:
> code $
命名空间Project.Console
{
类程序
{
static void Main(string [] args)
{
ProjectEntities pe = new ProjectEntities
}
}
}
MetadataException未处理
错误在构造函数。 无法加载指定的元数据资源
我做了大量的研究它似乎是这些资源的一个联系问题。我不能找到一个解决方案。
任何帮助。
我写了一篇冗长的关于调试此错误的指南。
I have a 3 tiered project.
1) Project.Data (EDMX file)
2) Project.Model (POCO's)
3) Project.Console (Console app)
I have added the connection string into the Project.Console
.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="ProjectEntities" connectionString="metadata=res://*/Project.csdl|res://*/Project.ssdl|res://*/Project.msl;provider=System.Data.SqlClient;provider connection string="Data Source=PC\SQLEXPRESS;Initial Catalog=Project;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
The Project.Model
is built using the EntityObject
T4 Template in VS2010. It generates a ObjectContext
class, with this constructor:
public ProjectEntities() : base("name=ProjectEntities", "ProjectEntities")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
I am just trying to instantiate the context
object, in the Project.Console
:
namespace Project.Console
{
class Program
{
static void Main(string[] args)
{
ProjectEntities pe = new ProjectEntities();
}
}
}
However, I am getting a MetadataException was unhandled
error at the constructor. Stating Unable to load the specified metadata resource.
I have done a ton of research (Googling), and found that it seems to be a linking issue on those resources. I cannot seem to find a resolution.
Any help is appreciated.
I wrote a lengthy guide to debugging this error a while back.
这篇关于EF4和连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!