none
Refreshing the data

    Question

  • I have a problem with data refresh.

    I have an app which uses a new datacontext for each query.  I feed the results of a query to the GUI (WPF) and can get a list of items (no problem).  The problem occurs when I add items (not to the list but to the database as other items which have the PK of one of the items as the FK of the new item.  All this works as the items are stored correctly.

    Now to refresh the GUI I refresh the original list.  The secondary items (those getting stored) are found as a property in the main item.  Those items are not refreshed as a result of the new query.  To do the inserts of the new data I use a completely new datacontext and when I refresh I use another new datacontext.

    Only when I close the app and run it again can I get the new items to show.


    Lloyd Sheen

    Wednesday, April 02, 2014 5:16 PM

Answers

  • Hello,

    >>Now to refresh the GUI I refresh the original list.

    How do you refresh the original list and is the list stored in memory? Is that like below:

    //Query the database to
    
                List<TableWithDateTime> originalList = new List<TableWithDateTime>();
    
                DataClasses1DataContext db = new DataClasses1DataContext();
    
                originalList = db.TableWithDateTimes.ToList();
    
    
                //Add a new entity with a new datacontext
    
                DataClasses1DataContext dbnew = new DataClasses1DataContext();
    
                TableWithDateTime t = new TableWithDateTime() { ID = 4, DateTimeColumn = DateTime.Now };
    
                dbnew.TableWithDateTimes.InsertOnSubmit(t);
    
                dbnew.SubmitChanges();
    
    
                //Rrefreh The Origianl List
    
                db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, originalList);
    

    It is, then unfortunately, the Refresh() method will only refresh the record which already exists the original list. For new records, it will not add them to the list. So you have to query it again.

    Or you can use the IQueryable<T> as:

    IQueryable<T> originalList;
    
                DataClasses1DataContext db = new DataClasses1DataContext();
    
                originalList = db.TableWithDateTimes.AsQueryable();
    

    This does not need to refresh database when we use the originalList, it will query database automatically.

    If I misunderstand, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 03, 2014 5:50 AM