none
Track changes on web form and generate CRUD operations using DBContext RRS feed

  • Question

  • I have a web form with about 200 textboxes, radio buttons and checkboxes and I want to be able to send the changes to the database whether they are inserts, updates or deletes. I know that the SubmitChanges method will generate these sql statements but in the past I have had to track these and generate the statements myself. Is there a preferred way to use EF 4.1  to help me with this? 
    Wednesday, February 1, 2012 4:04 AM

Answers

  • This is an architecture question.

    I recommend to you to use the Unit of Work pattern. When the request start you create the DataContext load the entity (or entities) you want to work. Work on them and finally when the request is going to return just save all changes.

     

    However... if you want you could maintain a DataContext per user flow of work.

    It is: You open a DataContext when the user start some heavy data modification work and call SaveChanges when the user accepts changes or simply destroy the DataContext if the user cancell operations. It would be more memory expensive.

    • Marked as answer by forwheeler Wednesday, February 1, 2012 7:47 PM
    Wednesday, February 1, 2012 2:50 PM

All replies

  • This is an architecture question.

    I recommend to you to use the Unit of Work pattern. When the request start you create the DataContext load the entity (or entities) you want to work. Work on them and finally when the request is going to return just save all changes.

     

    However... if you want you could maintain a DataContext per user flow of work.

    It is: You open a DataContext when the user start some heavy data modification work and call SaveChanges when the user accepts changes or simply destroy the DataContext if the user cancell operations. It would be more memory expensive.

    • Marked as answer by forwheeler Wednesday, February 1, 2012 7:47 PM
    Wednesday, February 1, 2012 2:50 PM
  • This is an architecture question.

    I recommend to you to use the Unit of Work pattern. When the request start you create the DataContext load the entity (or entities) you want to work. Work on them and finally when the request is going to return just save all changes.

     

    However... if you want you could maintain a DataContext per user flow of work.

    It is: You open a DataContext when the user start some heavy data modification work and call SaveChanges when the user accepts changes or simply destroy the DataContext if the user cancell operations. It would be more memory expensive.


    Thanks for the recommendation. I don't currently use MVC so I am looking for web form examples with Unit of Work pattern.
    Wednesday, February 1, 2012 4:16 PM