コード例 #1
0
        List <T> IDB.ExecuteToList <T>(string sql, IDbDataParameter[] pars)
        {
            IDB      db  = this;
            var      dt  = db.ExecuteToTable(sql, pars);
            List <T> lis = new List <T>();

            foreach (DataRow dr in dt.Rows)
            {
                lis.Add(ReflectionHelper.DataRowToModel <T>(dr));
            }
            return(lis);
        }
コード例 #2
0
        T IDB.ExecuteToModel <T>(string sql, System.Data.IDbDataParameter[] pars)
        {
            IDB db = this;
            var dt = db.ExecuteToTable(sql, pars);

            if (dt.Rows.Count == 0)
            {
                return(default(T));
            }
            else
            {
                return(ReflectionHelper.DataRowToModel <T>(dt.Rows[0]));
            }
        }
コード例 #3
0
        Dictionary <TKey, TValue> IDB.ExecuteToDic <TKey, TValue>(string sql, string key_name, IDbDataParameter[] pars)
        {
            IDB db = this;
            var dt = db.ExecuteToTable(sql, pars);

            Dictionary <TKey, TValue> dic = new Dictionary <TKey, TValue>();

            foreach (DataRow dr in dt.Rows)
            {
                if (!dic.Keys.Contains((TKey)Convert.ChangeType(dr[key_name], typeof(TKey))))
                {
                    dic.Add(
                        (TKey)Convert.ChangeType(dr[key_name], typeof(TKey)),
                        ReflectionHelper.DataRowToModel <TValue>(dr)
                        );
                }
            }

            return(dic);
        }