Base solution for your next web application
Open Closed

Question about nested transaction behaviour #93


User avatar
0
bvz created

I have reat the Unit Of Work documentation page, however, I have a question.

Consider this code:

public EntUserUnit AddUserUnit(EntUserUnit userUnit)
        {            
            Context.UserUnits.Add(userUnit);
            return userUnit;
        }

        public List<EntUserUnit> AddUserUnits(List<EntUserUnit> userUnits)
        {
            return userUnits.Select(AddUserUnit).ToList();
        }

This code is in an Application Service. The documentation states that a transaction will be started when I call theAddUserUnits(List<EntUserUnit> userUnits) method. This method then repeatedly calls another method, also on the Application Service.

If I send a list with 10 objects, will they all be added in the same transaction? If any one of them fails, will they all be rolled back?


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    They are considered a single transaction and all rolled back if an exception is thrown.

    See documentation: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#DocUowCallsOtherMethod">http://www.aspnetboilerplate.com/Pages/ ... therMethod</a>