/// <summary>
        /// Obtém o último objeto de uma lista de objetos vinda do banco de dados.
        /// </summary>
        /// <typeparam name="TDto">Tipo de objeto que deseja retornar na lista</typeparam>
        /// <param name="commandSql">Parametros necessários para realizar a consulta no banco de dados</param>
        /// <returns>Retorna um objeto preenchido com as informações do banco de dados</returns>
        protected TDto LastOrDefault <TDto>(CommandSql commandSql) where TDto : class, new()
        {
            AbstractDatabase database = DatabaseFactory.CreateDatabase(commandSql.EnumDatabaseType, commandSql.StringConnection);

            using (IDbConnection connection = database.CreateOpenConnection())
            {
                using (IDbCommand command = database.CreateCommand(commandSql.CommandText, connection))
                {
                    //Adiciona os parametros no command
                    if (commandSql.Parametros != null)
                    {
                        commandSql.Parametros.ForEach(x => command.Parameters.Add(x));
                    }

                    //Define configurações do command
                    command.CommandType    = commandSql.CommandType;
                    command.CommandTimeout = commandSql.CommandTimeout;
                    command.CommandText    = commandSql.CommandText;


                    //Converte o datareader em List

                    TDto entity = ObjectMapper.FillCollection <TDto>(command.ExecuteReader()).LastOrDefault();

                    return(entity);
                }
            }
        }
Ejemplo n.º 2
0
        public void ObjectMapper_FillObject_50000_Items()
        {
            var dataTable = new DataTable("ObjectTable");

            dataTable.Columns.Add("IntProp", typeof(int));
            dataTable.Columns.Add("StringProp", typeof(string));
            dataTable.Columns.Add("DateTimeProp", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp", typeof(Array));
            dataTable.Columns.Add("BitProp", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp", typeof(decimal));
            dataTable.Columns.Add("GuidProp", typeof(Guid));
            dataTable.Columns.Add("EnumProp", typeof(int));

            var bytearray = Encoding.ASCII.GetBytes("Hello This is test");
            var guid      = new Guid("e3b16c58-5737-410f-9548-227b9b34cf68");
            var enumValue = (int)TestObject.TestEnum.Two;

            for (int i = 0; i < 50000; i++)
            {
                dataTable.Rows.Add(
                    10,
                    "string",
                    DateTime.Today,
                    bytearray,
                    bytearray,
                    true,
                    12.99m,
                    guid,
                    enumValue);
            }

            List <TestObject> result = null;

            Measure("FillObject 50000 Items", 100, () =>
            {
                result = ObjectMapper.FillCollection <TestObject>(dataTable);
            });

            Assert.AreEqual(10, result[0].IntProp);
            Assert.AreEqual("string", result[0].StringProp);
            Assert.AreEqual(DateTime.Today, result[0].DateTimeProp);
            Assert.AreEqual(bytearray, result[0].ByteArrayProp);
            Assert.AreEqual(bytearray, result[0].ArrayProp);
            Assert.AreEqual(true, result[0].BitProp);
            Assert.AreEqual(12.99m, result[0].DecimalProp);
            Assert.AreEqual(new Guid("e3b16c58-5737-410f-9548-227b9b34cf68"), result[0].GuidProp);
            Assert.AreEqual(TestObject.TestEnum.Two, result[0].EnumProp);
        }
Ejemplo n.º 3
0
        public void ObjectMapper_FillLargeObject_50000_Items()
        {
            var dataTable = new DataTable("ObjectTable");

            dataTable.Columns.Add("IntProp", typeof(int));
            dataTable.Columns.Add("StringProp", typeof(string));
            dataTable.Columns.Add("DateTimeProp", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp", typeof(Array));
            dataTable.Columns.Add("BitProp", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp", typeof(decimal));

            dataTable.Columns.Add("IntProp2", typeof(int));
            dataTable.Columns.Add("StringProp2", typeof(string));
            dataTable.Columns.Add("DateTimeProp2", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp2", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp2", typeof(Array));
            dataTable.Columns.Add("BitProp2", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp2", typeof(decimal));

            dataTable.Columns.Add("IntProp3", typeof(int));
            dataTable.Columns.Add("StringProp3", typeof(string));
            dataTable.Columns.Add("DateTimeProp3", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp3", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp3", typeof(Array));
            dataTable.Columns.Add("BitProp3", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp3", typeof(decimal));

            dataTable.Columns.Add("IntProp4", typeof(int));
            dataTable.Columns.Add("StringProp4", typeof(string));
            dataTable.Columns.Add("DateTimeProp4", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp4", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp4", typeof(Array));
            dataTable.Columns.Add("BitProp4", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp4", typeof(decimal));

            dataTable.Columns.Add("IntProp5", typeof(int));
            dataTable.Columns.Add("StringProp5", typeof(string));
            dataTable.Columns.Add("DateTimeProp5", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp5", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp5", typeof(Array));
            dataTable.Columns.Add("BitProp5", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp5", typeof(decimal));

            dataTable.Columns.Add("IntProp6", typeof(int));
            dataTable.Columns.Add("StringProp6", typeof(string));
            dataTable.Columns.Add("DateTimeProp6", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp6", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp6", typeof(Array));
            dataTable.Columns.Add("BitProp6", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp6", typeof(decimal));

            dataTable.Columns.Add("IntProp7", typeof(int));
            dataTable.Columns.Add("StringProp7", typeof(string));
            dataTable.Columns.Add("DateTimeProp7", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp7", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp7", typeof(Array));
            dataTable.Columns.Add("BitProp7", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp7", typeof(decimal));

            dataTable.Columns.Add("IntProp8", typeof(int));
            dataTable.Columns.Add("StringProp8", typeof(string));
            dataTable.Columns.Add("DateTimeProp8", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp8", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp8", typeof(Array));
            dataTable.Columns.Add("BitProp8", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp8", typeof(decimal));

            dataTable.Columns.Add("IntProp9", typeof(int));
            dataTable.Columns.Add("StringProp9", typeof(string));
            dataTable.Columns.Add("DateTimeProp9", typeof(DateTime));
            dataTable.Columns.Add("ByteArrayProp9", typeof(Byte[]));
            dataTable.Columns.Add("ArrayProp9", typeof(Array));
            dataTable.Columns.Add("BitProp9", typeof(Boolean));
            dataTable.Columns.Add("DecimalProp9", typeof(decimal));

            var bytearray = Encoding.ASCII.GetBytes("Hello This is test");

            for (int i = 0; i < 50000; i++)
            {
                dataTable.Rows.Add(
                    10,
                    "string",
                    DateTime.Today,
                    bytearray,
                    bytearray,
                    true,
                    12.99m,
                    10,
                    "string",
                    DateTime.Today,
                    bytearray,
                    bytearray,
                    true,
                    12.99m,
                    10,
                    "string",
                    DateTime.Today,
                    bytearray,
                    bytearray,
                    true,
                    12.99m,
                    10,
                    "string",
                    DateTime.Today,
                    bytearray,
                    bytearray,
                    true,
                    12.99m,
                    10,
                    "string",
                    DateTime.Today,
                    bytearray,
                    bytearray,
                    true,
                    12.99m,
                    10,
                    "string",
                    DateTime.Today,
                    bytearray,
                    bytearray,
                    true,
                    12.99m,
                    10,
                    "string",
                    DateTime.Today,
                    bytearray,
                    bytearray,
                    true,
                    12.99m,
                    10,
                    "string",
                    DateTime.Today,
                    bytearray,
                    bytearray,
                    true,
                    12.99m,
                    10,
                    "string",
                    DateTime.Today,
                    bytearray,
                    bytearray,
                    true,
                    12.99m);
            }

            List <TestLargeObject> result = null;

            Measure("FillLargeObject 50000 Items", 100, () =>
            {
                result = ObjectMapper.FillCollection <TestLargeObject>(dataTable);
            });

            Assert.AreEqual(10, result[0].IntProp);
            Assert.AreEqual("string", result[0].StringProp);
            Assert.AreEqual(DateTime.Today, result[0].DateTimeProp);
            Assert.AreEqual(bytearray, result[0].ByteArrayProp);
            Assert.AreEqual(bytearray, result[0].ArrayProp);
            Assert.AreEqual(true, result[0].BitProp);
            Assert.AreEqual(12.99m, result[0].DecimalProp);

            Assert.AreEqual(10, result[0].IntProp2);
            Assert.AreEqual("string", result[0].StringProp2);
            Assert.AreEqual(DateTime.Today, result[0].DateTimeProp2);
            Assert.AreEqual(bytearray, result[0].ByteArrayProp2);
            Assert.AreEqual(bytearray, result[0].ArrayProp2);
            Assert.AreEqual(true, result[0].BitProp2);
            Assert.AreEqual(12.99m, result[0].DecimalProp2);

            Assert.AreEqual(10, result[0].IntProp3);
            Assert.AreEqual("string", result[0].StringProp3);
            Assert.AreEqual(DateTime.Today, result[0].DateTimeProp3);
            Assert.AreEqual(bytearray, result[0].ByteArrayProp3);
            Assert.AreEqual(bytearray, result[0].ArrayProp3);
            Assert.AreEqual(true, result[0].BitProp3);
            Assert.AreEqual(12.99m, result[0].DecimalProp3);

            Assert.AreEqual(10, result[0].IntProp4);
            Assert.AreEqual("string", result[0].StringProp4);
            Assert.AreEqual(DateTime.Today, result[0].DateTimeProp4);
            Assert.AreEqual(bytearray, result[0].ByteArrayProp4);
            Assert.AreEqual(bytearray, result[0].ArrayProp4);
            Assert.AreEqual(true, result[0].BitProp4);
            Assert.AreEqual(12.99m, result[0].DecimalProp4);

            Assert.AreEqual(10, result[0].IntProp5);
            Assert.AreEqual("string", result[0].StringProp5);
            Assert.AreEqual(DateTime.Today, result[0].DateTimeProp5);
            Assert.AreEqual(bytearray, result[0].ByteArrayProp5);
            Assert.AreEqual(bytearray, result[0].ArrayProp5);
            Assert.AreEqual(true, result[0].BitProp5);
            Assert.AreEqual(12.99m, result[0].DecimalProp5);

            Assert.AreEqual(10, result[0].IntProp6);
            Assert.AreEqual("string", result[0].StringProp6);
            Assert.AreEqual(DateTime.Today, result[0].DateTimeProp6);
            Assert.AreEqual(bytearray, result[0].ByteArrayProp6);
            Assert.AreEqual(bytearray, result[0].ArrayProp6);
            Assert.AreEqual(true, result[0].BitProp6);
            Assert.AreEqual(12.99m, result[0].DecimalProp6);

            Assert.AreEqual(10, result[0].IntProp7);
            Assert.AreEqual("string", result[0].StringProp7);
            Assert.AreEqual(DateTime.Today, result[0].DateTimeProp7);
            Assert.AreEqual(bytearray, result[0].ByteArrayProp7);
            Assert.AreEqual(bytearray, result[0].ArrayProp7);
            Assert.AreEqual(true, result[0].BitProp7);
            Assert.AreEqual(12.99m, result[0].DecimalProp7);

            Assert.AreEqual(10, result[0].IntProp8);
            Assert.AreEqual("string", result[0].StringProp8);
            Assert.AreEqual(DateTime.Today, result[0].DateTimeProp8);
            Assert.AreEqual(bytearray, result[0].ByteArrayProp8);
            Assert.AreEqual(bytearray, result[0].ArrayProp8);
            Assert.AreEqual(true, result[0].BitProp8);
            Assert.AreEqual(12.99m, result[0].DecimalProp8);

            Assert.AreEqual(10, result[0].IntProp9);
            Assert.AreEqual("string", result[0].StringProp9);
            Assert.AreEqual(DateTime.Today, result[0].DateTimeProp9);
            Assert.AreEqual(bytearray, result[0].ByteArrayProp9);
            Assert.AreEqual(bytearray, result[0].ArrayProp9);
            Assert.AreEqual(true, result[0].BitProp9);
            Assert.AreEqual(12.99m, result[0].DecimalProp9);
        }