Tuesday, 15 June 2010

Dapper.net dynamic OR query -


Use Dapr is new and needs a little help to pass me. Is a CCV file that I will read to generate a select statement.

Content Csv file looks like this:

  id, fromDate, toDate 1, 20100101,20110101201010101010101010101010101010101010101010101010101010101012.aspx ...  

I dynamically generated must be a query:

  SELECT * target Sable WHERE (with ID = 1 and 20,100,101 and 20,110,101 between CDT) or (ID = 2 and 20,110,101 and 20,120,101 between CDT) or ( id = 3 and 20,100,101 and 20,120,101 between CDT)  

how can I do this with Dapr do?

Why not just build your query?

After reading assuming that it makes your data you have CSV and hold it in classes:

  public class Data {public Inti ID {get; Set; } Public int fromDate {get; Set; } Public int ToDate {get; Set; }}  

I'll simply pass the query string just as:

  list & lt; String & gt; Line = new list & lt; String & gt; (); Forex Currency (Miscellaneous Data in List Data) // List Data ... List & lt; Data & gt; {String line = string.format ( "(id = {0} and {1} and CDT" data between {2}). ID data. Formedet data. Tudet); Lines.Add (line); } String additionalQuery = string.Join ("OR", myLines);  

And then ...

  var result = sqlConnection.Query  

will work just fine ...


No comments:

Post a Comment