Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

DomainDataSource deleting data RSS

15 replies

Last post Oct 12, 2010 09:06 AM by Enan

(0)
  • nlecren

    nlecren

    Member

    5 Points

    9 Posts

    DomainDataSource deleting data

    Jul 19, 2009 04:59 PM | LINK

    When removing an item from the DomainDataSource it seems as though the entity is deleted from the database on the SubmitChanges call but never leaves the DomainDataSource.Data property.  This results in the item being removed from the DataGrid and then added again.  It's almost as if removed items are never cleaned from the DomainDataSource.Data property.  Has anyone else been able to get this working?

    In my code I am loading parameters dynamically like this


                Parameter user_id = new Parameter();
                Parameter entry_date = new Parameter();
                Parameter load_serving_sizes = new Parameter();

                user_id.ParameterName = "user_id";
                user_id.Value = Globals.CurrentUser.id;

                entry_date.ParameterName = "entry_date";
                entry_date.Value = Globals.SelectedDate;

                load_serving_sizes.ParameterName = "load_serving_sizes";
                load_serving_sizes.Value = true;

                FoodContext context = FoodLogData.DomainContext as FoodContext;
                context = new FoodContext();

                FoodLogData.QueryParameters.Clear();
                FoodLogData.QueryParameters.Add(user_id);
                FoodLogData.QueryParameters.Add(entry_date);
                FoodLogData.QueryParameters.Add(load_serving_sizes);
                FoodLogData.Load();

     

    Deletes look like this

    (FoodLogData.DomainContext as FoodContext).FoodLogEntries.Remove(entry);

    FoodLogData.SubmitChanges();

     

    FoodLogData is the DomainDataSource

     I have to create a new DataContext in the load since there is a calendar control on the page and I want the DataGrid to display only entries for a given day but no matter what I do the Data property just keeps appending entities to the list when the user selects a new day.  I could'nt find any way to bind to the new entries only so I create a new DataContext instead. 

    I'm not sure I understand why the Data property just holds onto every entity ever loaded.  Is there no way to clear the data from the DomainDataSource dynamically?  Seems strange that you would want this control holding an instance of every entity ever loaded.

  • narayans

    narayans

    Member

    36 Points

    30 Posts

    Re: DomainDataSource deleting data

    Jul 21, 2009 07:00 AM | LINK

    Hi nlecern,

    Seems like you have a similar problem to mine. I am adding entities instead of Removing them:

     (FoodLogData.DomainContext as FoodContext).FoodLogEntries.Add(entry);

    and the DataGrid bound to the Data property does not update (becase the Data property does not update).

     Here's my post: http://silverlight.net/forums/p/111826/252328.aspx#252328

    Looks like a bug in the July CTP however, I have yet to get confirmation.... I'm keeping an eye out for a workaround....

     

  • nlecren

    nlecren

    Member

    5 Points

    9 Posts

    Re: DomainDataSource deleting data

    Jul 21, 2009 01:41 PM | LINK

     Interesting, I did end up finding out that you can set the MergeOption during the LoadingData event on the DomainDataSource, however it doesn't actually make any difference.  I got everything working by eliminating the DomainDataSource and working with specific DomainContext objects in code.

    The MergeOption doesn't work in that solution either so I have to create a new DomainContext every time I want to refresh the data.

  • narayans

    narayans

    Member

    36 Points

    30 Posts

    Re: DomainDataSource deleting data

    Jul 21, 2009 09:16 PM | LINK

    Great - glad you found a workaround.

    I understand that I can bind directly to the DomanContext, however I have implemented a base Entity selector class that does not (and should not) know the Entiy Type so the DomainDataSource.Data field was perfect. I hope to get some acknowledgement on whether it is indeed a bug or if it is this a permanent change to how DomanDataSource.Data works. Keeping my fingers crossed :)

  • JeffHandley

    JeffHandley

    Participant

    764 Points

    146 Posts

    Microsoft

    Re: DomainDataSource deleting data

    Jul 21, 2009 10:36 PM | LINK

    This does in fact sound like a bug.  We'll investigate it.  Obviously, after submitting changes, any deleted records should not come back. :-)

    Thanks,
    Jeff Handley

    DomainDataSource

  • narayans

    narayans

    Member

    36 Points

    30 Posts

    Re: DomainDataSource deleting data

    Jul 21, 2009 11:07 PM | LINK

    Hi Jeff,

    Thanks for your response. Can you confirm that conversely, any pending Add's should show up in the DomainDataSource.Data prior to submitting changes?

    If I call DomainDataSource.DomainContext.Entity.Add(entity).... the DomainDataSource.Data used to reflect the change in the May CTP. This was nice becase your DataGrid would then show pending Adds.

     I read your blog post on this subject and appreciate that this is not a simple issue.

    Thanks

  • JeffHandley

    JeffHandley

    Participant

    764 Points

    146 Posts

    Microsoft

    Re: DomainDataSource deleting data

    Jul 21, 2009 11:31 PM | LINK

    I responded to the question about adds over on your related thread for that.  Hope this helps!

    http://silverlight.net/forums/p/111826/254733.aspx#254733

    Thanks,
    Jeff Handley

    DomainDataSource

  • nlecren

    nlecren

    Member

    5 Points

    9 Posts

    Re: DomainDataSource deleting data

    Jul 22, 2009 02:55 AM | LINK

     Jeff,

    Thanks for looking into this.  My preference was to stick with the DomainDataSource solution to take advantage of the built in paging, sorting, filtering, grouping, etc...  But with the deleted records staying in the Data property I wasn't able to do that.  If it helps the records are removed from the database after the SubmitChanges call is made.

    Nick


  • nlecren

    nlecren

    Member

    5 Points

    9 Posts

    Re: DomainDataSource deleting data

    Jul 24, 2009 05:00 PM | LINK

     Jeff,

    I have attempted to use various techniques to remove items from the IEditableCollectionView DataView interface but no matter what removed items just reappear after the call to Submit changes.  For example if you do the following:

    ((IEditableCollectionView)Source.DataView).Remove(customer);
    ((IEditableCollectionView)Source.DataView).CommitEdit();


    Source.SubmitChanges();

    At first the DataGrid will look correct, however if you call Source.Load the removed entities again appear in the DataView even though they no longer exist in the database.  Another way to repro is as simple as adding a DataPager to the mix and calling the above code.  If you then move to the next page and then back to the original page the DataGrid will contain the removed entries yet again but at the bottom of the list.  It's almost as if the DataView is arbitrarily adding a RemovedItems collection contents to the bottom of the DataGrid no matter what you do.

    Hope this helps
    Thanks
    Nick

  • EugenUS

    EugenUS

    Member

    96 Points

    120 Posts

    Re: Re: DomainDataSource deleting data

    Aug 13, 2009 09:40 AM | LINK

    Any updates on how to delete a record from DataGrid? I have same odd behavior, it gets deleted from DB but not from DataGris. Damn, if I'd only knew I'd have so much troubles with unfinished product as RIA I'd never would started this project using it :(