Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the best way to implement a search in the pattern DAL?
    text
    copied!<p>I usually declare my DAL classes overwriting search methods whenever possible as the example below:</p> <pre><code>public class clsAsd { private AdConn oConn; public clsAsd(ref AdConn Connection) { oConn = Connection; } private string sqlSearch(string DocType, string Status, string Aaa) { return " AND x.tp_doc = '" + DocType + "'\r\n" + " AND x.co_status IN (" + Status + ")\r\n" + " AND x.aaa = '" + Aaa + "'\r\n"; } public List&lt;clsQwe&gt; search(string DocType, string Status, string Aaa, bool IncDel) { return search(sqlSearch(DocType, Status, Aaa), IncDel); } private string sqlSearch(string DocType, string Status, string Aaa, string Bbb) { string sSQL = sqlSearch(DocType, Status, Aaa) + (Bbb != "" ? " AND x.bbb = '" + Bbb + "'\r\n" : ""); return sSQL; } public List&lt;clsQwe&gt; search(string DocType, string Status, string Aaa, string Bbb, bool IncDel) { return search(sqlSearch(DocType, Status, Aaa, Bbb), IncDel); } private List&lt;clsQwe&gt; search(string Where, bool IncDel) { string sSQL; sSQL = "SELECT\r\n"; sSQL += " b.aaa, c.bbb, x.*\r\n"; sSQL += "FROM asd x, qwe b, zxc c\r\n"; sSQL += "WHERE x.www = b.www\r\n"; sSQL += " AND x.zzz = c.zzz\r\n"; sSQL += Where; if (!IncDel) sSQL += " AND x.del IS NULL\r\n"; sSQL += "ORDER BY x.www"; // Connection + Run SQL // List to get results List&lt;clsQwe&gt; lstRet = new List&lt;clsQwe&gt;(); // Row to add in list clsQwe oX; while (oReader.Read()) { oX = new clsQwe(); // Add all data lstRet.Add(oX); } // Return data return lstRet; } } </code></pre> <p>My question is: is this a good practice?</p> <p>I should use one method for each different search? example:</p> <pre><code>public class clsAsd { private AdConn oConn; public clsAsd(ref AdConn Connection) { oConn = Connection; } public List&lt;clsQwe&gt; search1(string DocType, string Status, string Aaa, bool IncDel) { } public List&lt;clsQwe&gt; search2(string DocType, string Status, string Aaa, string Bbb, bool IncDel) { } public List&lt;clsQwe&gt; search3(string DocType, string Status, string Aaa, string Bbb, string Ccc, bool IncDel) { } private List&lt;clsQwe&gt; search(string Where, bool IncDel) { } } </code></pre> <p>How could I improve this class?</p> <p>I'm considering implementing only one search method that receives the class (clsQwe) as a parameter. I check each property of this class and create the where clause in accordance with properties populated.</p> <p>This approach is interesting?</p> <p>Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload