New Posts New Posts RSS Feed: Property Changed on Detached Entities
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Property Changed on Detached Entities

 Post Reply Post Reply
Author
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post Topic: Property Changed on Detached Entities
    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
Back to Top
stephenmcd1 View Drop Down
DevForce MVP
DevForce MVP


Joined: 27-Oct-2009
Location: Los Angeles, CA
Posts: 166
Post Options Post Options   Quote stephenmcd1 Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down