Assuming your parameters are fixed (usually intended for stored procedures), the main time you need DynamicParameters is that you generate SQL on-the = fly to match a complex flexible query) - then the aspect of the parameter is just as simple :
new { Plan = plan }
In this case, a function of an anonymous type of the compiler is used to determine that the parameter must have the name Plan , have the type string and have a value taken from the Plan variable.
If we assume that the stored procedure select results (rather than return , which must be encoded separately) on one line, then the easiest way to read this is:
var myvalue = connection.Query<int>("storeProcmem_Plan", new { Plan = plan }, CommandType.StoredProcedure).First();
General and non-general API switches between typed results and dynamic results - both are used, but <int> seems appropriate here. .First() is a standard LINQ operation that translates from IEnumerable<T> to T by selecting the first value (and throwing an exception if there was none) - you can also use Single() , FirstOrDefault() or SingleOrDefault() in depending on the exact semantics you want.
For completeness, if you used a non-generic API, you need to know the column name - basically it will be:
dynamic row = connection.Query("storeProcmem_Plan", new { Plan = plan }, CommandType.StoredProcedure).First(); int myvalue = row.ColumnName;
Marc gravell
source share