LinqDataSource DataContext Pending changes RRS feed

  • Question

  • I have a GridView that has a DataSourceID for a LinqDataSource with a Linq to SQL DataContext (called DataClassesDataContext) in the ContextTypeName.

    I want to be able to insert, update and delete in the gridview without saving directly in the database, that should only happen when you click the Save button. From what i've read the LinqDataSource creates a DataClassesDataContext instance, but i don't think it's a permanent datacontext and i can't access it except on the ContextCreated event.

    How can i do "pending changes" if i don't have a permanent datacontext and i can't access the DataClassesDataContext of the LinqDatasource to allow me to call InsertOnSubmit (to create new entries), DeleteOnSubmit(to remove entries) and to update whatever needs to be updated and then call SubmitChanges() in the Save button click event?

    Thursday, August 9, 2012 10:03 AM


  • You can make your own datacontext and submit your changes there, the datacontext is a lightweight and short lived object so it doesn't matter that is not permanent and that you don't have access to one specific datacontext as multiple users can modify a db... so code away.


    • Marked as answer by Alexander Sun Monday, September 3, 2012 9:25 AM
    Thursday, August 9, 2012 2:19 PM