none
LINQ Best practice for Multiuser App RRS feed

  • Question

  • What's the best practice for reflecting multiuser database changes with LINQ ? In ADO.net I would refill the dataset using a tableadapter but I'm not sure how to do the equivalent in LINQ. Should I create a new datacontext class everytime I want to get the latest data, or is there a way to refresh the data ? I've tried the datacontext.refresh method but this does not seem to work . . .

     

     

    Thursday, March 27, 2008 10:16 AM

Answers

  • Are you referring to updating existing objects with changed values or updating collections with new objects/records?

     

    Querying a Table<T> property on the DataContext should always go back to the database to pick up new records - any collections you are populating from this would need to be refreshed.

     

    You can update existing objects with changes from the database by calling the Refresh method on your DataContext passing in the mode you want (keep any uncomitted local changes or overwrite them from the database) AND the collection of objects you wish to update.

     

    This shold work fine but if it does not please let me know.

     

    Regards,

     

    [)amien

     

    Wednesday, May 28, 2008 6:57 PM
    Moderator