Laurent
Laurent

Reputation: 41

EF and WPF Datagrid binding issue

Is it possible to change the name of the server the EF connect to on the fly?

I have the same database on 5 servers (different environments, Dev, Test, UAT...) and would like to write a dashboard application to extract the same information from each server in turn by just selecting the environment from a DDL.

I am using Entity Framework 4/WPF/C#. The new ObservableCollection(context.EntitySet) is bound to the WPF DataGrid in XAML. This works fine. the xaml grid binding is as follow

<grid:RadGridView ItemsSource="{Binding EPolicies}" IsReadOnly="True" RowDetailsVisibilityMode="VisibleWhenSelected" RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False">

in the view model I call the following code

             entities = new EpolicyEntities(environmentConnStr);
            customTexts = new ObservableCollection<C_CustomTextType>(from i in entities.C_CustomTextType select i);
            languages = new ObservableCollection<C_Language>(from i in entities.C_Language select i);
            userTypes = new ObservableCollection<C_UserType>(from i in entities.C_UserType select i);
            EPolicies = new ObservableCollection<EPolicy>(from e in entities.EPolicies select e);

entities is the ObjectContext representing the database that I connect to

The first time it works fine but the second time even thoguh I can see the new values in the EPolicies object, the grid is not being refreshed as I would want EPolicies is a property defined as below public ObservableCollection EPolicies { get { return ePolicies; } set { ePolicies = value; OnPropertyChanged(() => EPolicies); } } Can somebody help me please? thanks

Anyone done this?

Upvotes: 2

Views: 315

Answers (1)

Laurent
Laurent

Reputation: 41

Okay I found out.

The issue was that the property

public ObservableCollection EPolicies {                     

  get { return ePolicies; } 

  set {
      ePolicies = value; OnPropertyChanged(() => EPolicies); 
  }
}

is calling the OnpropertyChanged but not the Base.OnPropertyChanged. Not sure why it works that way might be that the event is not being bubbled up. Does anybody has an answer?

Upvotes: 2

Related Questions