Hi,
I have a random issue with the PropertyChanged event of an entity in a generic ViewModel.
Often the events are never fired on my ViewModel, there is no real pattern to reproduce the issue. When I create an instance of it, it will either always fire the event for any change on a property of my entity or NEVER fire it (during the same SL session).
The property "Currentcompany" I monitor is declared like this :
// TCompany is an abstract base class (TPH inheritance)
// TConvention is irrelevant here, it is just to allow to declare a bindablecollection of type TConvention populated
// by the method LoadConventionsAsync() (which is only fired in CurrentCompanyEntityPropertyChanged)
public class ContactItemViewModel<TCompany, TConvention> : PropertyChangedBase, IDisposable
where TCompany : Company
where TConvention : Convention
{
private T _currentCompany;
public T CurrentCompany
{
get { return _currentCompany; }
set
{
if (_currentCompany != null)
_currentCompany.EntityFacts.EntityPropertyChanged -= CurrentDebiteurEntityPropertyChanged;
_currentCompany = value;
// The EntityFacts property is declared like in Temphire
_currentCompany.EntityFacts.EntityPropertyChanged += CurrentDebiteurEntityPropertyChanged;
NotifyOfPropertyChange(() => CurrentCompany);
}
}
// if I set a breakpoint in this method, it might enter on every change on the property CurrentCompany
// or NEVER !! (with no code change, no rebuild)
private void CurrentCompanyEntityPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName.Equals(Debiteur.EntityPropertyNames.Company_Id) ||
e.PropertyName.Equals(Debiteur.EntityPropertyNames.DateDebut))
{
LoadConventionsAsync();
}
}
}
Any idea what could cause the issue ?
The only error I get (I log errors for devforce, cocktail and caliburn) is from devforce and happen at the end of the all the caliburn binding in my viewmodel.
(CALIBURN) ViewModelBinder INFO: Binding Convention Applied: Element CurrentCompany_DateEnd.
Une exception de première chance de type 'System.InvalidOperationException' s'est produite dans IdeaBlade.EntityModel.Edm.dll
I am using :
- Silverlight 5
- DevForce 7.0.3
- Cocktail 2.2.0
- Postsharp 2.1.7.28
- Caliburn 1.4
Note : I use the EntityPropertyChanged in many others ViewModel and I didn't yet had this kind of issue. The major difference with others ViewModels is here I monitor a generic property.
Still about this issue, I have another one which may be related.
Scenario : I have an entity A with a required navigation property B. The user has first to select in a combobox an entity C which will be use to filter the collection of B. In rare case the collection of B can be empty once filtered, so I expect to have a validation error in that case.
Problem : When it tries to set Null to the navigation property it raise an exception (I see it only in the log, it doesn't go till the unhandledException of my bootstrapper). After this exception happen it's not possible anymore to use the EntityPropertyChanged in differents instances of this ViewModel. I can close my viewmodel, reopen it (using a different entitymanger) but the event won't works anymore.
Edited by kdev - 11-Jan-2013 at 3:38am