You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My scenario :
Logging the database access, including parameters infos, like this:
// business logic layer
public class DemoBLL
{
public void M1(p1, p2, p3)
{
DynamicParameters dynPars = new DynamicParameters();
if(...)
dynPars.Add(parname1, parvalue1);
if(...)
dynPars.Add(parname2, parvalue2);
QueryL(conn.Query(sql, dynPars,...);
}
public void M2(p4, ...)
{
DynamicParameters dynPars = new DynamicParameters();
if(...)
dynPars.Add(...);
if(...)
dynPars.Add(...);
QueryL(conn.Query(sql, dynPars,...);
}
}
// data access layer
public class DemoDAL
{
public void QueryL(sql, dynPars,...)
{
// log the query infos
logger.Info("Sql Text:" + sql);
// I wish i could do like this
foreach (var dp in dynPars.Parameters) // but there's no public 'Parameters' member, so these code won't effect
{
sb.AppendFormat("{{Name:{0}, Type:{1}, Value:{2}, Direction:{3}}}, ",
dp.Value.Name, dp.Value.DbType,
Convert.ToString(dp.Value.Value),
dp.Value.ParameterDirection);
}
conn.Query(sql, dynPars)
}
}
I hope if we could foreach DynamicParameters.parameters, that will be very very useful!
To me that strongly suggests you're over-using the dynamic parameters... It
is far more efficient to use simple argument types (usually anonymous
types) than dynamic parameters.
I certainly wouldn't expose the field. We could think about making it
iterable, but I'd need to think what the impact is re expansions etc.
On 23 Sep 2017 4:53 p.m., "zhangleixp" ***@***.***> wrote:
My scenario :
Logging the database access, including parameters infos, like this:
`// business logic layer
public class DemoBLL
{
public void M1(p1, p2, p3)
{
DynamicParameters dynPars = new DynamicParameters();
if(...)
dynPars.Add(parname1, parvalue1);
if(...)
dynPars.Add(parname2, parvalue2);
QueryL(conn.Query(sql, dynPars,...);
}
}
// data access layer
public class DemoDAL
{
public void QueryL(sql, dynPars,...)
{
// log the query infos
logger.Info("Sql Text:" + sql);
// I wish i could do like this
foreach (var dp in dynPars.Parameters) // but there's no public 'Parameters' member, so these code won't effect
{
sb.AppendFormat("{{Name:{0}, Type:{1}, Value:{2}, Direction:{3}}}, ", dp.Value.Name, dp.Value.DbType, Convert.ToString(dp.Value.Value), dp.Value.ParameterDirection);
}
conn.Query(sql, dynPars)
}
}
`
I think if we could foreach DynamicParameters.parameters, that will be
very very useful!
Another scenarios:
[#304]
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#849>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABDsPXX4vCTYHtKekPFuJpaWXXDJiyMks5slSmTgaJpZM4Phl91>
.
I have the same issue actually. Just like how I can use DbParameterCollection to loop through the list of parameters, it would be nice if I can also loop through the DynamicParameters' collection of parameters. At the very least, please make it iterable for readonly access. My use case is for logging and/or messaging purposes (ex. constructing messages that includes raw input and output values from a stored procedure call). Thanks!
To me that strongly suggests you're over-using the dynamic parameters... It is far more efficient to use simple argument types (usually anonymous types) than dynamic parameters.
@mgravell : "More efficient" meaning "less typing" or "executes faster"? The terse style of using an anonymous for parameters looks very nice... but in my experience there is rarely an occasion to use it, because you need DynamicParameters just to check the return value.
I would also like to be able to iterate parameters in DynamicParameters for logging with type (including string vs. ansi string), size, and direction.
Activity
mgravell commentedon Sep 24, 2017
etmendz commentedon Sep 24, 2017
I have the same issue actually. Just like how I can use DbParameterCollection to loop through the list of parameters, it would be nice if I can also loop through the DynamicParameters' collection of parameters. At the very least, please make it iterable for readonly access. My use case is for logging and/or messaging purposes (ex. constructing messages that includes raw input and output values from a stored procedure call). Thanks!
zhangleixp commentedon Sep 25, 2017
@mgravell
Thanks for for reply.
Making DynamicParameters.parameters iterable is enough for my scenario, and same as @etmendz , just readonly access.
BTW, DynamicParameters is a very useful. The short of anonymous types is that once it is created it will be hard to add more fields.
Dana2917 commentedon Sep 14, 2020
@mgravell : "More efficient" meaning "less typing" or "executes faster"? The terse style of using an anonymous for parameters looks very nice... but in my experience there is rarely an occasion to use it, because you need DynamicParameters just to check the return value.
I would also like to be able to iterate parameters in DynamicParameters for logging with type (including string vs. ansi string), size, and direction.