none
Entity Data Model and Database Transaction commit and rollback RRS feed

  • Question

  • Hi,

    I have a transaction based application that gets orders from customers and records them with an Active status on my Database. If the user decides to fill this order, he/she can do so by way of a button on an appropriate form. By pressing this button the client sends a status update to the server. The server in updating the order status also needs to add a transaction entry to a transactions entity and also update inventory. In this case the transaction needs to be 1)update order status 2)add transaction entry 3)update inventory... If successful then commit all changes to the database and if not rollback to an unchanged state and inform the user that the update was unsuccessful.

    I am using the Entity Data Model and am having trouble figuring out how to use the moethod savechanges in conjunction with refresh to cater for rollback within a try/catch scope. Can you please help?

    Tuesday, January 10, 2012 11:53 PM

Answers

  • On 1/10/2012 6:53 PM, Detox wrote:
    > Hi,
    >
    > I have a transaction based application that gets orders from customers
    > and records them with an Active status on my Database. If the user
    > decides to fill this order, he/she can do so by way of a button on an
    > appropriate form. By pressing this button the client sends a status
    > update to the server. The server in updating the order status also needs
    > to add a transaction entry to a transactions entity and also update
    > inventory. In this case the transaction needs to be 1)update order
    > status 2)add transaction entry 3)update inventory... If successful then
    > commit all changes to the database and if not rollback to an unchanged
    > state and inform the user that the update was unsuccessful.
    >
    > I am using the Entity Data Model and am having trouble figuring out how
    > to use the moethod savechanges in conjunction with refresh to cater for
    > rollback within a try/catch scope. Can you please help?
    >
     
    you use the system.transaction.setcomplete
     
     
    • Proposed as answer by Allen_MSDNModerator Thursday, January 12, 2012 3:41 AM
    • Marked as answer by Detox Thursday, January 12, 2012 10:14 AM
    Wednesday, January 11, 2012 12:01 AM

All replies

  • On 1/10/2012 6:53 PM, Detox wrote:
    > Hi,
    >
    > I have a transaction based application that gets orders from customers
    > and records them with an Active status on my Database. If the user
    > decides to fill this order, he/she can do so by way of a button on an
    > appropriate form. By pressing this button the client sends a status
    > update to the server. The server in updating the order status also needs
    > to add a transaction entry to a transactions entity and also update
    > inventory. In this case the transaction needs to be 1)update order
    > status 2)add transaction entry 3)update inventory... If successful then
    > commit all changes to the database and if not rollback to an unchanged
    > state and inform the user that the update was unsuccessful.
    >
    > I am using the Entity Data Model and am having trouble figuring out how
    > to use the moethod savechanges in conjunction with refresh to cater for
    > rollback within a try/catch scope. Can you please help?
    >
     
    you use the system.transaction.setcomplete
     
     
    • Proposed as answer by Allen_MSDNModerator Thursday, January 12, 2012 3:41 AM
    • Marked as answer by Detox Thursday, January 12, 2012 10:14 AM
    Wednesday, January 11, 2012 12:01 AM
  • Hi Detox,

    Welcome to MSDN Forum.

    @darnold924's link provide you a good sample to explain how to manage transaction in Entity Framework. Please refer to the link, I think it will solve the issue.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, January 12, 2012 3:41 AM
    Moderator
  • many thanks. that did the trick. just for the benefit of others, I did have to include System.Transactions as a reference in my web application before I could gain access to the TransactionScope object, but all seems to have gone well with the commit/rollback methodology with the Entity Data Model.
    Thursday, January 12, 2012 10:17 AM
  • On 1/12/2012 5:17 AM, Detox wrote:
    > many thanks. that did the trick. just for the benefit of others, I did
    > have to include System.Transactions as a reference in my web application
    > before I could gain access to the TransactionScope object, but all seems
    > to have gone well with the commit/rollback methodology with the Entity
    > Data Model.
     
    If you say you are using EF in the codebehind file of an ASP.NET Web
    page, then it's ok since you are using Linq with EF.
     
    Here is the reason why.
     
     
    With recent rampant SQL Injection attacks being ran on SQL Server
    worldwide against ASP and ASP.NET Web pages with over a mullion
    compromised Web sites, then Linq can help to stop it.
     
    Best practice is to do database access in the Data Access Layer, and not
    up at the codebehind file of an ASP.NET Web page.
     
    Thursday, January 12, 2012 10:49 AM