【发布时间】:2012-05-18 21:28:02
【问题描述】:
我正在使用 Entity Framework 编写一个 WPF 应用程序,并且我有两个控件,Window 和 UserControl,它们嵌入在 Window 中。 UserControl 设计器工作正常,但 Window 设计器返回异常:
The specified named connection is either not found in the configuration, not
intended to be used with the EntityClient provider, or not valid.
UserControl 代码隐藏中的异常点位于我创建实体实例的位置。
public partial class Table : UserControl
{
private MyEntities entity;
public Table()
{
InitializeComponent();
entity = new MyEntities();
}
}
当我运行应用程序时,一切正常。
编辑
我在这里找到了解决方案:WPF designer won't load with entity framework,虽然我使用的是 VS2010,而且前段时间这种方法(在同一个地方创建实体实例)效果很好,但我不知道是什么破坏了它。
【问题讨论】:
-
听起来像是在尝试创建一个对象上下文 - 要么将该代码移动到另一个地方,要么根据您是否处于设计模式而使其成为条件
标签: c# wpf entity-framework