Print Page | Close Window

Property Changed on Detached Entities

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2674
Printed Date: 15-May-2025 at 2:12am


Topic: Property Changed on Detached Entities
Posted By: stephenmcd1
Subject: Property Changed on Detached Entities
Date Posted: 12-May-2011 at 1:50pm
I have some entities that I often use without being associated with an Entity Manager (that is, they are detached).  So far, I haven't run into any major issues except for one.  If an exception is thrown by somebody watching the PropertyChanged event, Dev Force tries to do special logic.  It looks to see if the entity is being loaded.  But in my case, that check fails because the entity is not in an entity manger.  And unfortunately, that means that I get a very unhelpful "NullReferenceException" and my original exception gets swallowed.  The problem code that I'm running into is in EntityWrapper and looks something like this:

   protected internal virtual void OnPropertyChanged(PropertyChangedEventArgs e)
    {
      if (this.PropertyChanged != null)
      {
        try
        {
          this.PropertyChanged.Invoke(this, e);
        }
        catch
        {
          if (!this.EntityManager.IsLoadingEntity)
          {
            throw;
          }
        }
      }
    }

It seems like if the condition was changed to 'if (this.EntityManager == null || !this.EntityManager.IsLoadingEntity)', then it would behave fine for detached entities.  I know this might be a weird use case, but I'm hoping it would be a pretty simple and low-risk change.

Thanks,
-Stephen



Replies:
Posted By: stephenmcd1
Date Posted: 20-Jun-2011 at 4:51pm
As an update to anybody else that might stumble across this topic, the issue I described above has been fixed as of 6.1.1.0.

Thanks IdeaBlade!

-Stephen



Print Page | Close Window