我剛剛創建了一個用戶控件。 此控件還使用我的靜態實體框架類來加載兩個組合框。 一切都很好,運行沒有問題。設計和運行時正在工作。 然後當我停止應用程序時,包含我的UserControl的所有表單在設計時不再工作。我只看到兩個錯誤:UserControl中的EF無法看到app.config?
錯誤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;
}
}
}
一些邏輯,我的用戶發生加載在組合框的數據:
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並不是用來這樣使用的。 – Aaronaught