コード例 #1
0
        public IEnumerable <T> ReadList <T>()
        {
            Type type = typeof(T);
            Func <IDataReader, object> act = null;
            object obj      = null;
            int    cachekey = SqlMapper.GetHashKey(connctionStr, type);

            if (SqlMapper.QueryMultiReaderActionCache.ContainsKey(cachekey))
            {
                act = SqlMapper.QueryMultiReaderActionCache[cachekey];
            }
            else
            {
                act = this.ReadImpl <T>(type, reader);
            }
            while (reader.Read())
            {
                obj = act(reader);
                if (obj == null)
                {
                    continue;
                }
                yield return((T)obj);
            }
            ReadNextResult();
        }
コード例 #2
0
        public T Read <T>()
        {
            Type type = typeof(T);
            Func <IDataReader, object> act = null;
            object obj      = null;
            int    cachekey = SqlMapper.GetHashKey(connctionStr, type);

            if (SqlMapper.QueryMultiReaderActionCache.ContainsKey(cachekey))
            {
                act = SqlMapper.QueryMultiReaderActionCache[cachekey];
            }
            else
            {
                act = this.ReadImpl <T>(type, reader);
            }
            reader.Read();
            obj = act(reader);
            ReadNextResult();
            return((T)obj);
        }
コード例 #3
0
        private IEnumerable <T> QueryCommandList <T>(string querySql, DbParameter[] paramters = null)
        {
            Contract.Requires <AggregateException>(!querySql.IsNullOrSpace(), "查询SQL语句不能为空");
            DbConnection dbConn = CreateNativeContection();
            DbDataReader reader = null;

            try
            {
                reader = QueryCommandReader(querySql, paramters);
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        yield return(SqlMapper.Load <T>(map._type, reader, SqlMapper.GetHashKey(this.connectionString, querySql)));
                    }
                }
                reader.Close();
                yield return(default(T));
            }
            finally
            {
                reader.Close();
            }
        }
コード例 #4
0
        public int Insert <T>(T model)
        {
            string sql = SqlMapper.CreateInsertMethod(model, SqlMapper.GetHashKey(connectionString, GetDataMap <T>().tableName));

            return(CommandImpl(sql));
        }
コード例 #5
0
        public int Update <T>(T model, string where)
        {
            string sql = SqlMapper.CreateUpdateMethod(model, SqlMapper.GetHashKey(connectionString, GetDataMap <T>().tableName + where));

            return(CommandImpl(sql));
        }
コード例 #6
0
        //根和聚合集合
        public TReturn Query <TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(string querySql, Delegate act, object paramters = null) where TReturn : new()
        {
            TReturn            tReturn = new TReturn();
            List <DbParameter> param   = CreateParater(paramters);
            var reader = this.QueryCommandReader(querySql, param.ToArray());

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    tReturn = SqlMapper.MultiMap <TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(act, reader, SqlMapper.GetHashKey(connectionString, querySql));
                }
            }
            reader.Close();
            return(tReturn);
        }
コード例 #7
0
        private List <DbParameter> CreateParater(object paramters)
        {
            List <DbParameter> param = new List <DbParameter>();
            Type paramtersType       = null;

            if (!paramters.IsNullOrSpace())
            {
                paramtersType = paramters.GetType();
                param         = SqlMapper.GetParams(paramters, paramtersType, dbprovider, SqlMapper.GetHashKey(this.connectionString, paramtersType));
            }

            return(param);
        }