public CRUDSql GetSelectSql(T searchPara, string tableName, string orderBy, List <string> selectFields = null) { // ComDBFun ComDBFun = new ComDBFun(bOrcl); Dictionary <string, object> dic = DtModelConvert <T> .GetPropertity(searchPara); List <string> whereParas = dic.Keys.ToList(); object[] values = dic.Values.ToArray(); for (int i = dic.Values.Count - 1; i >= 0; i--)//比较值为空的不参与比较 { if (dic.Values.ToList()[i] == null || string.IsNullOrEmpty(dic.Values.ToList()[i].ToString())) { whereParas.Remove(dic.Keys.ToList()[i]); dic.Remove(dic.Keys.ToList()[i]); } } string whereSql = new ComDBFun(DBBaseAttr).GetWhereCondition(whereParas, "and"); string fds = (selectFields == null || selectFields.Count <= 0) ? "*" : string.Join(",", selectFields); orderBy = string.IsNullOrEmpty(orderBy) ? "" : "order by " + orderBy; string sql = string.Format("select {0} from {1} {2} {3}", fds, tableName, whereSql, orderBy); CRUDSql res = new CRUDSql() { Sql = sql }; res.PMS = GetDbParametersFromDic(dic); return(res); }
public CRUDSql GetInsertSql <M>(M model, string tableName, bool bParameterizedQuery) { Dictionary <string, object> dic = DtModelConvert <T> .GetPropertity(model); ComDBFun ComDBFun = new ComDBFun(DBBaseAttr); string textParas = ComDBFun.GetSQLText(dic.Keys.ToList(), (bParameterizedQuery ? null : dic.Values.ToList())); string sql = "insert into " + tableName + textParas; CRUDSql insertSql = new CRUDSql() { Sql = sql }; if (bParameterizedQuery) { insertSql.PMS = GetDbParametersFromDic(dic); } return(insertSql); }