Exemplo n.º 1
0
        public ICollection <T> SelectAll <T>() where T : class, new()
        {
            OrmMap map         = mappingPool[typeof(T)];
            string selectQuery = map.BuildSelectAllQuery();

            using (DbConnection connection = GetOpenConnection())
            {
                DbCommand command = connection.CreateCommand();
                command.CommandText = map.BuildSelectAllQuery();

                DbDataReader    reader  = command.ExecuteReader();
                DbReaderAdapter adapter = new DbReaderAdapter(reader, map);
                return(adapter.GetMultipleResult <T>());
            }
        }
Exemplo n.º 2
0
        public T SelectById <T>(object id) where T : class, new()
        {
            OrmMap map            = mappingPool[typeof(T)];
            string whereStatement = String.Format("{0}=@id", map.ID);
            string selectQuery    = map.BuildSelectWhereQuery(whereStatement);

            using (DbConnection connection = GetOpenConnection())
            {
                DbCommand command = connection.CreateCommand();
                command.CommandText = selectQuery;

                DbParameter param = command.CreateParameter();
                param.DbType        = map.GetDbType(map.ID);
                param.ParameterName = "@id";
                param.Value         = id;
                command.Parameters.Add(param);

                DbDataReader    reader  = command.ExecuteReader();
                DbReaderAdapter adapter = new DbReaderAdapter(reader, map);
                return(adapter.GetSingleResult <T>());
            }
        }