none
OrderBy causing problems with BindingSource RRS feed

  • Question

  • Hi,

    I have a usercontrol bound to a child collection of a LINQtoSQL entity.

    I need the collection to be synchronised when I add then delete the same record but before I call SubmitChanges. This works as expected except when I add in an OrderBy clause.

    ie

    1. If I don't use the OrderBy clause it works perfectly:

    ucClientConsultations.BindingSource = new BindingSource(this._client.ClientConsultations, null); 

     - Add new record, delete it from the DataGridView

     - this._client.ClientConsultations.Count = 0 which is correct.

    2.  However if I add an OrderBy clause it doesn't remove the newly added item from the collection.

    ucClientConsultations.BindingSource = new BindingSource(this._client.ClientConsultations.OrderByDescending(a => a.Date_of_Visit), null);

     - Add new record, delete it from the DataGridView

    -  this._client.ClientConsultations.Count = 1 which is incorrect as the record was deleted. 

    It seems the OrderBy clause is causing the problem - any ideas what I’m missing here?

    Monday, September 24, 2012 9:27 PM

All replies

  • I need the collection to be synchronised when I add then delete the same record but before I call SubmitChanges. This works as expected except when I add in an OrderBy clause.

    Hi dizzyj,

    What is LINQtoSQL entity? linq to sql, entity framework or something else?

    Base on my understanding, the code will not implement the change to database before call submitchanges method(both liq to sql and ef). How van the count changes?

    Here is a demo. Could you please modify it to help us to reproduce this issue? Thanks.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, September 27, 2012 10:49 AM
    Moderator
  • Hi - it is LinqToSQL.

    Basically I am trying to keep changes made in memory in synch across forms (without using a global context). I need to be able to add / remove items to the child grids (eg Order) and have the parent Customer keep up to date - ie Customer.Orders must still reflect the correct Orders, including those that have been adeded then subsequently deleted in memory.

    When users are happy with their changes then they call SubmitChanges.

    I have uploaded a sample app here

    Thanks


    • Edited by dizzyj Monday, October 1, 2012 3:10 AM
    Monday, October 1, 2012 3:09 AM
  • Hi dizzyj,

    I'm not able to access the sample.

    Could you please double check if you uploaded it?

    If you had, please make sure it is share with everyone. Thanks.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 1, 2012 12:00 PM
    Moderator
  • Hi - it is now in the Public folder so hopefully you can reach it here.

    Thanks


    • Edited by dizzyj Monday, October 1, 2012 9:01 PM
    Monday, October 1, 2012 8:55 PM