Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you were to put the Business Rule Check (ie limit check) inside a transaction, it will be fine. That is</p> <ol> <li>User Clicks button that fires the Add Proposal Command</li> <li>Code starts a new transaction. See <a href="https://stackoverflow.com/questions/646318/nhibernate-with-transactionscope/4085328#4085328">here for how I suggest you use transactions</a> </li> <li>Load the RequestForProposal object from the db, or Refresh it. I suggest you use an upgrade lock.</li> <li>Add the new proposals to the root. Check the limit constraint, throw an exception it fails.</li> <li>Commit the transaction</li> </ol> <p>Doing it this way you are using the databases <a href="http://en.wikipedia.org/wiki/Concurrency_control" rel="nofollow noreferrer">concurrency controls</a>. I don't think there is any other way of doing it. </p> <p>This will create some contention, but you can take a few steps to minimize that. Namely make sure in Step 3 that the db column you select by has an index on it. This will cause a row lock, instead of a page lock.</p> <p>If you use an Upgrade lock in step 3, this will avoid deadlocks. Basically when the second users submits a proposal for the same Aggregate Root the db will not let you read it until the first transaction has committed.</p> <p>You should also consider adding a db index on Proposal.RequestForProposalId, it will help performance as that is the column the Proposal's are loaded on. I'm not 100% if it helps minimize the scope of any locks on that table, but it might ...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload