私は通常、以下の例のように、可能な限り検索メソッドを上書きする DAL クラスを宣言します。
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<clsQwe> 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<clsQwe> search(string DocType, string Status, string Aaa, string Bbb, bool IncDel) {
return search(sqlSearch(DocType, Status, Aaa, Bbb), IncDel);
}
private List<clsQwe> 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<clsQwe> lstRet = new List<clsQwe>();
// Row to add in list
clsQwe oX;
while (oReader.Read()) {
oX = new clsQwe();
// Add all data
lstRet.Add(oX);
}
// Return data
return lstRet;
}
}
私の質問は次のとおりです。これは良い習慣ですか?
異なる検索ごとに 1 つの方法を使用する必要がありますか? 例:
public class clsAsd {
private AdConn oConn;
public clsAsd(ref AdConn Connection) { oConn = Connection; }
public List<clsQwe> search1(string DocType, string Status, string Aaa, bool IncDel) { }
public List<clsQwe> search2(string DocType, string Status, string Aaa, string Bbb, bool IncDel) { }
public List<clsQwe> search3(string DocType, string Status, string Aaa, string Bbb, string Ccc, bool IncDel) { }
private List<clsQwe> search(string Where, bool IncDel) { }
}
どうすればこのクラスを改善できますか?
クラス (clsQwe) をパラメーターとして受け取る検索メソッドを 1 つだけ実装することを検討しています。このクラスの各プロパティを確認し、入力されたプロパティに従って where 句を作成します。
このアプローチは面白いですか?
ありがとうございました。