MongoRepository documentation
IRepositoryT, TKeyRequestStart Method |
Lets the server know that this thread is about to begin a series of related operations that must all occur
on the same connection. The return value of this method implements IDisposable and can be placed in a using
statement (in which case RequestDone will be called automatically when leaving the using statement).
Namespace: MongoRepository
Assembly: MongoRepository.Net45 (in MongoRepository.Net45.dll) Version: 1.6.11.0 (1.6.11.0)
Syntax
IDisposable RequestStart()
Function RequestStart As IDisposable
IDisposable^ RequestStart()
abstract RequestStart : unit -> IDisposable
Return Value
Type: IDisposableA helper object that implements IDisposable and calls RequestDone() from the Dispose method.
Remarks
Sometimes a series of operations needs to be performed on the same connection in order to guarantee correct
results. This is rarely the case, and most of the time there is no need to call RequestStart/RequestDone.
An example of when this might be necessary is when a series of Inserts are called in rapid succession with
SafeMode off, and you want to query that data in a consistent manner immediately thereafter (with SafeMode
off the writes can queue up at the server and might not be immediately visible to other connections). Using
RequestStart you can force a query to be on the same connection as the writes, so the query won't execute
until the server has caught up with the writes.
A thread can temporarily reserve a connection from the connection pool by using RequestStart and
RequestDone. You are free to use any other databases as well during the request. RequestStart increments a
counter (for this thread) and RequestDone decrements the counter. The connection that was reserved is not
actually returned to the connection pool until the count reaches zero again. This means that calls to
RequestStart/RequestDone can be nested and the right thing will happen.
See Also