Dapper.net dynamic OR query -
new using dapper , need little help. have .csv file read dynamically generate select statement.
the .csv file contents this:
id,fromdate,todate 1,20100101,20110101 2,20110101,20120101 3,20100101,20120101 etc...
the query need dynamically generate should be:
select * targettable (id = 1 , cdate between 20100101 , 20110101) or (id = 2 , cdate between 20110101 , 20120101) or or (id = 3 , cdate between 20100101 , 20120101)
how can dapper?
why not building query?
assuming have data in form after reading csv , push classes:
public class data { public int id { get; set; } public int fromdate { get; set; } public int todate { get; set; } }
i'd pass query string:
list<string> lines = new list<string>(); foreach (var data in listdata) // listdata ... list<data> { string line = string.format("(id = {0} , cdate between {1} , {2})", data.id,data.fromdate, data.todate); lines.add(line); } string additionalquery = string.join(" or ", mylines);
and then...
var result = sqlconnection.query<myquerydata>(string.format("select * targettable {0}", additionalquery));
will work fine...
Comments
Post a Comment