Update datacontext RRS feed

  • Question

  • Hi,


    I have an application that uses Linq to sql. My problem is that I don't know how to update changes between users.

    In my Form I have a datacontext class that is a class member variable. I use this to fill three BindingSource instances that is bound to three DataGridViews. When a user select one row in the first grid I use the datacontext to fill the next and so on. Having the datacontext as a member variable I can easely make updates from all the grids with the SubmitChanges method.


    But the problem is that when user A makes some changes and then user B reloads the data, user B just get the cached data. So user B never see the new values in the database, it also creates error if user B tries to make new changes because he is working on "old" data and that throws an exception when SubmitChanges is called. I cannot disable object tracking because I need to call the SubmitChanges to update the data.


    I looked at the datacontext.Refresh method, but I could not make it work.

    How can I make this work without creating a new instance of the datacontext class each time I have to "update" the data?

    Tuesday, September 23, 2008 6:23 PM

All replies

  • Hi

    As I khonw datacontex use its cashe intelligently, so one way is to creating a new instance of datacontext. and here is a sample for DataContext.Refresh()  Method.

    DataContext.Refresh(RefreshMode.OverwriteCurrentValues, Object entity);

    Refresh() Method also have some other overload for refreshing collection of entity.

    I hope this be helpfull.
    Wednesday, September 24, 2008 4:30 AM