New Posts New Posts RSS Feed: EntityPropertyChanged isn't fired when a property change
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

EntityPropertyChanged isn't fired when a property change

 Post Reply Post Reply
Author
kdev View Drop Down
Groupie
Groupie
Avatar

Joined: 03-Jan-2013
Posts: 83
Post Options Post Options   Quote kdev Quote  Post ReplyReply Direct Link To This Post Topic: EntityPropertyChanged isn't fired when a property change
    Posted: 07-Jan-2013 at 1:00am
I found out what was the problem. I had a base class for this module, in which I had a Start method to load the root entity.
I wrote it like this :
            ActiveUnitOfWork.Companies.WithIdAsync(entityId[0]).ContinueWith(
                task => CurrentCompany = task.Result);
After some inverstigation I found out the items I was creating in the VM ContactItemViewModel were created on a different thread (and I didn't get the invalid cross thread acceee exception).
Correcting the line to this resolved my issue :
            ActiveUnitOfWork.Companies.WithIdAsync(entityId[0]).ContinueWith(
                task => CurrentCompany = task.Result, TaskScheduler.FromCurrentSynchronizationContext());


Edited by kdev - 11-Jan-2013 at 3:39am
Back to Top
kdev View Drop Down
Groupie
Groupie
Avatar

Joined: 03-Jan-2013
Posts: 83
Post Options Post Options   Quote kdev Quote  Post ReplyReply Direct Link To This Post Posted: 04-Jan-2013 at 2:45am
With a test project I can't reproduce it, I will continue to investigate.
Back to Top
kdev View Drop Down
Groupie
Groupie
Avatar

Joined: 03-Jan-2013
Posts: 83
Post Options Post Options   Quote kdev Quote  Post ReplyReply Direct Link To This Post Posted: 03-Jan-2013 at 4:46pm
hi sbelini,

The problem is I don't know how to reproduice it, half of the time it just doesn't works.
Sometimes the first time I create the viewmodel it will works. If I close it and create a new one, this one won't fire the event. 
Sometimes it works perfectly for both.
Sometimes it never works for both.

There is no pattern. That's why I wonder if the 2nd issue could be related. If at some point an internal exception is thrown in devforce maybe it could  prevent the event to be fired ?

I will take try to reproduce the 2nd case without caliburn/cocktail.




Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 03-Jan-2013 at 2:32pm
kdev,
 
I can't tell what exactly could be causing this issue.
When you mentioned
"it will either always fire the event for any change on a property of my entity or NEVER fire it"
You are most likely missing a small detail that differentiates the steps of when it works and when it doesn't.
In any case, we'd need a sample reproducing the issue.
 
As for the second issue, please also provide a reproducible test case so we can test the behavior.
 
When creating a repro case please do not include Cocktail/Caliburn, so we can isolate the DevForce problem without external parts adding complexity.
 
sbelini.
Back to Top
kdev View Drop Down
Groupie
Groupie
Avatar

Joined: 03-Jan-2013
Posts: 83
Post Options Post Options   Quote kdev Quote  Post ReplyReply Direct Link To This Post Posted: 03-Jan-2013 at 12:56pm
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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down