none
In WPF When ClearCache the datacontext it not updated in BindingList in Linq to sql. Why????????

    Pergunta

  • Hello All,

                 When i clear all changes in datacontext but it not updated in BindingList . And it not reflected in binded grid.

     #region Clear Datacontxt
    
    const BindingFlags FLAGS = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
    
    var method = Dc.GetType().GetMethod("ClearCache", FLAGS);
                method.Invoke(Dc, null);
    
    Dc.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues); 
    
     #endregion
    
                
     dataGrid1.Items.Refresh();
                

    The datacontext is cleard but not updating in grid Why??????????????????

    I am using Linq ,in WPF C#


    • Editado JophyJob quinta-feira, 23 de fevereiro de 2012 07:08
    quinta-feira, 23 de fevereiro de 2012 07:07

Respostas

  • Hi JophyJob,

    I have tested the code, 'ClearCache' method is really be invoked. But from the code, after clear the cache, I don't find a rebind for the gridview. I'm not familiar with WPF, but I think before calling 'gridview1.Items.Refresh()', you may need to query out the records and rebind again. The cache is cleared after using reflection to invoke the 'ClearCache' method, for the binding and refresh, if rebind couldn't solve the issue, I suggest you to post the issue in WPF Forum to see if some WPF specialists have some ideas about it.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    terça-feira, 28 de fevereiro de 2012 06:57

Todas as Respostas

  • Hi JophyJob,

    Welcome to MSDN Forum.

    I'm not familiar with WPF, but from the code, I couldn't find the code about 'ClearCache'. Is it really clear the cache successfully? Or maybe after clear the cache, the control need to bind again.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    sexta-feira, 24 de fevereiro de 2012 06:28
  • Hi Allen,

                  'ClearCache' Working fine and it clear all data from the Datacontext.GetChangeSet(). But I bid datagerid using IBindingList it not updated so grid show old values that i updated ..

    public DataClasses1DataContext Dc;
    IBindingList list;
    Dc = new DataClasses1DataContext();
    list = Dc.Employees.GetNewBindingList();

    How can i update the Grid ..
    sexta-feira, 24 de fevereiro de 2012 06:37
  • Hi jophyJob,

    What's the 'GetNewBindingList' method is? And, I'm not familiar with WPF Binding Control, but I think after updating databae, you can try to retrieve the data and make sure whether they have updated, and bind it to the control.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    segunda-feira, 27 de fevereiro de 2012 07:50
  • Hello Allen,

                   Hear i attach a link to the sample that i am working

    Link :GridRefresh,ClearCache            and if not work Copy this :

    https://skydrive.live.com/redir.aspx?cid=d54b0993343a8868&resid=D54B0993343A8868!117&parid=root

    segunda-feira, 27 de fevereiro de 2012 07:58
  • Hi JophyJob,

    I have tested the code, 'ClearCache' method is really be invoked. But from the code, after clear the cache, I don't find a rebind for the gridview. I'm not familiar with WPF, but I think before calling 'gridview1.Items.Refresh()', you may need to query out the records and rebind again. The cache is cleared after using reflection to invoke the 'ClearCache' method, for the binding and refresh, if rebind couldn't solve the issue, I suggest you to post the issue in WPF Forum to see if some WPF specialists have some ideas about it.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    terça-feira, 28 de fevereiro de 2012 06:57
  • Hello Allen,

                   I bind the grid in the page using complex binding linq query's .I geting the page at run time and  not have the binding query that time, is any option to get the Binding qury from the page or grid ?....

    segunda-feira, 5 de março de 2012 14:40
  • Hi JohyJob,

    Do you mean you want to get query statement from the UI?

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    terça-feira, 6 de março de 2012 01:47
  • Hello Allen,

                     yes.. i need binging query from the grid

    sexta-feira, 9 de março de 2012 13:04
  • Hi JophyJob,

    It need you to build the query statement dynamically. But Linq to SQL don't support dynamically building. There's a workaround, you can use Dynamic Linq to do that. Make sure the columns which are bound to UI, and pass them as parameters to the dynamic linq.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    segunda-feira, 12 de março de 2012 08:04
  • Hi Allen,

                 Thank u for that information .................... 

    segunda-feira, 12 de março de 2012 12:46