Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:10:09+00:00 2026-05-31T13:10:09+00:00

I am having a problem with DomainContext.RejectChanges() and reflecting the rollback in the UI.

  • 0

I am having a problem with DomainContext.RejectChanges() and reflecting the rollback in the UI. Here is my scenario.

  1. I have a Model (Entity) generated for use with RIA services (I’ll call it Foo)
  2. I have a ViewModel that wraps Foo and extends it (I’ll call it FooViewModel)
  3. I have a View that is using Binding to display and update data using the FooViewModel
  4. I have an “outer” ViewModel that holds an ObservableCollection of FooViewModels
  5. The “outer” View has a list box bound to the ObservableCollection

So essentially there is a listbox of FooViewModels on one screen…when you select an item a childwindow is displayed to edit that particular FooViewModel. The FooViewModel is serving both the listbox and the childwindow.

Editing works just fine. A change in the childwindow reflects in the listbox immediately because I am calling RaisePropertyChanged() when the viewmodel properties are updated.

However, If I perform a DomainContext.RejectChanges()…the underlying entity gets rolled back (all changes reverted as expected)…however the FooViewModel isn’t aware that this change has occurred and thus the UI isn’t updated. If I reselect the item in the listbox on the first screen, the childwindow is displayed with the rolled back changes (which is what I want). The listbox still isn’t updated though.

When I reject changes, if I kludge a RaiseProperyChanged() for the field that I changed…the UI listbox does update.

How do I get the UI to update when the underlying entity is rejected?? And how do I do it without tracking what properties of the viewmodel were rolledback? There has to be an easy way to accomplish this that I am just missing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:10:10+00:00Added an answer on May 31, 2026 at 1:10 pm

    Something you could try is use the PropertyChanged event on the underlying entity Foo to trigger a RaisePropertyChanged pass on the FooViewModel properties.

    so making some assumptions (so this code make sense):

    1. You have a private variables in your FooViewModel
      private Foo _foo;
      private DomainContext _context;

    2. You have a method on your FooViewModel that is calling RejectChanges() on your domain context.

    Like so:

    public void RejectChanges()
    {
        _context.RejectChanges();
    }
    
    1. We have a method that raises the PropertyChanged event on our FooViewModel

    Like so:

    private void RaisePropertyChanged(string propertyName)
    {
        var handler = PropertyChanged;
    
        if(handler != null)
            handler(this, new PropertyChangedEventArgs(propertyName);
    }
    

    Ok, now we have that established, lets have a look at exactly what happens when you call RejectChanges() on a domain context.

    When you call RejectChanges() this bubbles down through the DomainContext to its EntityContainer, then to each EntitySet in that container and then to each Entity in the set.

    Once there (and in the EntitySet), it reapplies the original values if there was any, removes the entity if it was added, or adds it if it was deleted. If there was changes to the values, then it applies them back to the properties.

    So theoretically, all the RaisePropertyChanged(), that are generated in the entity properties, should be triggered.

    NOTE: I haven’t actually tested this. If this isn’t the case, then none of this works 😛

    So we can hook into PropertyChanged event of the Foo entity, and raise the PropertyChanged event on our FooViewModel.

    so our RejectChanges() method might look like this:

        public void RejectChanges()
        {
            Func<object, PropertyChangedEventArgs> handler = (sender, e) =>
                {
                    RaisePropertyChanged(e.PropertyName);
                };
    
            _foo.PropertyChanged += handler;
    
            _context.RejectChanges();
    
            _foo.PropertyChanged -= handler;
        }
    

    So we hook up an event handler to our Foo entity, which calls the FooViewModel.RaisePropertyChanged method with the property name that is changing on the Foo entity.

    Then we reject changes (which triggers the property changes),

    then we unhook the event handler.

    Pretty long winded, but I hope this helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are having problem with the server migration. We have one application that are
I'm having problem when running my Windows Forms program. In the program, I have
m having problem in passing parameter to controller action, i have done the following
Hi I'm having problem refreshing my listview after Async operation. I have a simplecursoradapter,
It seems the world is awash with people having problems deploying RIA WCF services,
I am having problem in using this font in my Application. I have imported
Im having problem's adding map markers to gmaps using jquery. Here is my code
I´m having problem using validation on DropDownListFor ... My Model : public class User
I having problem figuring howto preserve the present state ...Let say I have selected
I'm having problem with global variable in PHP. I have mysqli config file which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.