EF in a UserControl can't see the app.config?
- by Sven
I just created a user control.
This control also makes use of my static Entity Framework class to load two comboboxes.
All is well and runs without a problem. Design and runtime are working.
Then when I stop the application all the forms that contain my UserControl don't work any more in design time. I just see two errors:
Error1:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
Error 2:
The variable ccArtikelVelden is either undeclared or was never assigned.
(ccArtikelVelde is my UserControl)
Runtime everything is still working
My static EF Repositoy class:
public class BSManagerData
{
private static BSManagerEntities _entities;
public static BSManagerEntities Entities
{
get
{
if (_entities == null)
_entities = new BSManagerEntities();
return _entities;
}
set
{
_entities = value;
}
}
}
Some logic happening in my UserControl to load the data in the comboboxes:
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";
}
The only way to make my forms work again, design time, is to comment out the EF part in the UserControl (see above) and rebuild.
It's very strange, everything is in the same assembly, same namespace (for the sake of simplicity).
Anyone an idea?