简体   繁体   中英

c# razor webpages wrapper for the Database helper with dynamic parameters

I've inherited a web site project that has been written in c#/razor WebPages and uses the Database library for data access that returns dynamic objects.

I need to add some audit logging on all the SQL that is executed. I started to write a little wrapper around the database library like below so that I could add the logging centrally;

public static IEnumerable<dynamic> dbExecute(string sql, Array paramslist)
{

    //sql would be eg "SELECT TOP 5 ID FROM TABLENAME WHERE ID > @0"
    //IN THIS CASE THE PARAMSLIST WOULD ONLY HAVE ONE ENTRY

    var db = Database.Open("DatabaseName");
    var queryResult = db.Query(sql, CANT PUT AN ARRAY HERE);
    return queryResult;

}

I quickly ran into a problem with parameters as it wont accept an array =(.

Does anyone have any ideas how I can handle the dynamic parameters here..?

Thanks

This was my fault, being stupid...

public static IEnumerable<dynamic> dbExecute(string sql, Array paramslist)

should have been

public static IEnumerable<dynamic> dbExecute(string sql, string[] paramslist)

My apologies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM