| DbContextDoInConnectionT Method (DbContextActionWithResultT) |
Execute an action and return the result. If no current connection exists, it will establish a connection to the customer database and close it afterwards.
An existing connection will be reused. Inside the action, the connection is available as
Connection.
Namespace:
Omada.OE.AppLogic
Assembly:
Omada.OE.AppLogic (in Omada.OE.AppLogic.dll) Version: 15.0.0.0
Syntaxpublic static T DoInConnection<T>(
DbContextActionWithResult<T> action
)
Parameters
- action
- Type: Omada.OE.AppLogicDbContextActionWithResultT
The action to execute
Type Parameters
- T
- The return type of the action
Return Value
Type:
TThe result of the action
Examples
This will reuse an existing connection if one exists on the thread. Normally, it is not necessary to specify the type parameter
T, since the compiler can infer it.
int count = DbContext.DoInConnection(
delegate { return (int) (DbContext.Connection.GetCommand().ExecuteScalar("SELECT COUNT(*) FROM someTable"));
See Also