【发布时间】:2015-11-09 02:29:58
【问题描述】:
我刚刚创建了一个用户控件。 此控件还使用我的静态实体框架类来加载两个组合框。 一切都很好,运行没有问题。设计和运行时正在工作。 然后,当我停止应用程序时,包含我的 UserControl 的所有表单在设计时都不再工作。我只看到两个错误:
错误1: 指定的命名连接在配置中未找到,不打算与 EntityClient 提供程序一起使用,或者无效。
错误 2:
变量ccArtikelVelden 要么未声明,要么从未赋值。
(ccArtikelVelde 是我的UserControl)
运行时一切仍在运行
我的静态 EF Repositoy 类:
public class BSManagerData
{
private static BSManagerEntities _entities;
public static BSManagerEntities Entities
{
get
{
if (_entities == null)
_entities = new BSManagerEntities();
return _entities;
}
set
{
_entities = value;
}
}
}
在我的 UserControl 中发生了一些逻辑来加载组合框中的数据:
private void LaadCbx()
{
cbxCategorie.DataSource = (from c in BSManagerData.Entities.Categories
select c).ToList();
cbxCategorie.DisplayMember = "Naam";
cbxCategorie.ValueMember = "Id";
}
private void cbxCategorie_SelectedIndexChanged(object sender, EventArgs e)
{
cbxFabrikant.DataSource = from f in BSManagerData.Entities.Fabrikants
where f.Categorie.Id == ((Categorie)cbxCategorie.SelectedItem).Id
select f;
cbxFabrikant.DisplayMember = "Naam";
cbxFabrikant.ValueMember = "Id";
}
在设计时让我的表单再次工作的唯一方法是注释掉 UserControl 中的 EF 部分(见上文)并重建。 很奇怪,所有东西都在同一个程序集中,同一个命名空间(为了简单起见)。
谁有想法?
【问题讨论】:
-
我一看到“静态实体框架类”这个词就停止了阅读。别那样做。现在。
ObjectContext不适合以这种方式使用。
标签: c# entity-framework user-controls windows-forms-designer