none
datacontext.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues,entitie) not Working When insert pending in Linq ,WPF ??????? RRS feed

  • Question

  • Hello All,

                  When i refresh linq to Sql datacontext   that have pending insert or delete operation . I do  refresh with

    "datacontext.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues,entitie) ;"

    throw error  ........ How to solve the error ........

    error message is :

    "An object specified for refresh is pending insert and cannot be refreshed."



    • Edited by JophyJob Saturday, February 25, 2012 8:18 AM
    Saturday, February 25, 2012 8:17 AM

Answers

  • Hi JophyJob;

    According to the exception you are trying to Refresh an entity that is to be inserted on the next SubmitChanges. This would mean that the entity does not yet exist in the database and can not be refreshed. So to get it back to its original state would mean to delete on the next SubmitChanges. So to remove it before inserting it into the database the following should work.

    datacontext.EntitySetName.DeleteOnSubmit(entitie);

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Saturday, February 25, 2012 3:34 PM
  • Hi JophyJob,

    Welcome to MSDN Forum.

    datacontext.Refresh(RefreshMode.OverwriteCurrentValues, item) will forces the Refresh method to override all the current values with the values from the database. A entity with the state of added has not exist in database, so it can't be override, a entity with the state of deleted which value of the property hasn't change in the database, so it will not change. What I know about Linq to SQL is that, about binding to WPF Data Control, I suggest you to post in WPF Forum.

    Best Regards


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

    Friday, March 2, 2012 8:52 AM
    Moderator

All replies

  • Hi JophyJob;

    According to the exception you are trying to Refresh an entity that is to be inserted on the next SubmitChanges. This would mean that the entity does not yet exist in the database and can not be refreshed. So to get it back to its original state would mean to delete on the next SubmitChanges. So to remove it before inserting it into the database the following should work.

    datacontext.EntitySetName.DeleteOnSubmit(entitie);

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Saturday, February 25, 2012 3:34 PM
  • Hello Fernando,

                            I bind the entity with IBindingList so when i remove it not reflect in Datacontext or binding list. and the table is binded to a grid it also have to get the change that i am making .... .Real Problem is that When i Clear the datacontext by

    const BindingFlags FLAGS = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
    
    var method = datacontext.GetType().GetMethod("ClearCache", FLAGS);
    
    method.Invoke(datacontext, null);

    It delete all changeset But it not reflect in grid ..
    Saturday, February 25, 2012 4:05 PM
  • Hi JophyJob;

    My knowledge of WPF is not great so If you are willing to post your project to Windows Live Skydrive I will take a look at it. If you do upload to Skydrive please zip the complete project before uploading. If you can't do that when one of the moderators check in I am sure they will assist.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Sunday, February 26, 2012 2:16 PM
  • Hello Fernando,

                         Link to Gridcontrol Refresh this is the link to file zip. it have a example ,of a simple  grid and add button and a refresh button

    i also in case not working link addres is:

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

    Monday, February 27, 2012 5:02 AM
  • Hi JophyJob;

    Lets say that you click on AddDataToGrid1 and fill in the information to insert a new Employee. Lets also say you modified some other records in Employee and then you click on RefreshGrid1. What do you what to happen in that event and what do you want the grid to have in it as far as the modified records and the newly added record that has not yet been saved to the database?

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Monday, February 27, 2012 5:02 PM
  • Hello Fernando,

                           I Need the data in the database to be lodeed to the grid when i press Refresh Button . And i am in mainWindow and grid is in page that inserted on frame of main window .All databindings are done on page . Is any option to do it , that is to load the data that present in the database to grid by removing any pending cahnges that in the Datacontex, that i want to cancel the insert and delete operations made to the data context.I also tryed the Code

    datacontext.Refresh(RefreshMode.OverwriteCurrentValues, item);
    But it only working for Update . and it rise error for other . Even the "ClearCache" Clear the Pending changes but Not reflected in grid. and after that no operations like inserts or updates not reflect in Datacontest some time .. Why ?..............................

    • Edited by JophyJob Tuesday, February 28, 2012 4:34 AM
    Tuesday, February 28, 2012 4:27 AM
  • Hi JophyJob,

    Welcome to MSDN Forum.

    datacontext.Refresh(RefreshMode.OverwriteCurrentValues, item) will forces the Refresh method to override all the current values with the values from the database. A entity with the state of added has not exist in database, so it can't be override, a entity with the state of deleted which value of the property hasn't change in the database, so it will not change. What I know about Linq to SQL is that, about binding to WPF Data Control, I suggest you to post in WPF Forum.

    Best Regards


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

    Friday, March 2, 2012 8:52 AM
    Moderator