views:

43

answers:

1

I am running into an issue with refreshing data on a page after doing an update through WCF RIA Services.

I have a ComboBox and a Button on a page. The user chooses an item from the ComboBox, and then clicks the Button. This does a soft delete of the item in the database(setting "Active" = false). However, I would like for it to be removed from the ComboBox after the updated has completed. This is where my problem is.

InventorySystemDomainContext context = new InventorySystemDomainContext();

private void btnDelete_Click(object sender, RoutedEventArgs e)
{
    Cigarette c = cboCigarette.SelectedItem as Cigarette;
    c.Active = false;

    SubmitOperation so = context.SubmitChanges();
    so.Completed += delegate (object s, EventArgs es)
    {
        LoadComboBox();
    }
}

private void LoadComboBox()
{
    cboCigarettes.DataSource = null;
    cboCigarettes.DataSource = context.Cigarettes;
    context.Load(context.GetCigarettesQuery());
}

When the Delete button is clicked, all the code runs. However, the deleted item is still in the ComboBox(even though the record has been updated in the database). If I refresh the page, the item is gone from the ComboBox.

Any ideas?

PS: I wrote this code from memory since I don't have the code with me. So I may have forgotten a line, but I think I got all the relevant lines.

+1  A: 

Have you tried setting the ComboBox.ItemsSource to the Entities collection return from the Load method? EntitySets (context.Cigarettes) are aggregating (they contain data from multiple loads) while LoadOperation.Entities is not (it only contains data from the load it represents).

Kyle McClellan
I have not tried that. I didn't know there was a difference. I will try that.
Eclipsed4utoo
that worked. switch it to `LoadOperation lo = context.Load(context.GetCigarettesQuery());``cboCigarettes.DataSource = lo.Entities;`and it worked. thanks.
Eclipsed4utoo