views:

85

answers:

0

Hi all,

any helper class for reduce code lines using ent Library:

        Database db = DatabaseFactory.CreateDatabase("ConnectionStrings.Oracle.D04PES01");
        using (DbCommand cm = db.GetStoredProcCommand("TBL_POC_TEST_TIPOS.TBL_POC_TEST_TIPOS_FBY_PK"))
        {
            db.AddInParameter(cm, "P_ID_TEST_TIPOS", DbType.String, id);
            cm.Parameters.Add(CreateCursorParameter("P_REFCURSOR"));

            // Using "using" will cause both the DataReader and connection to be 
            // closed. (ExecuteReader will close the connection when the 
            // DataReader is closed.)
            using (IDataReader dataReader = db.ExecuteReader(cm))
            {
                if (dataReader.Read())
                {
                    factory.Add(dataReader);
                }
                //while (dataReader.Read())
                //{
                //    factory.Add(dataReader);
                //    break;
                //}
                return factory.Entity;
            }
        }

For example, get code like this (or more better than this):

Entidades.Tipos t = null;
            IBuilderEntityFromDataReader<Entidades.Tipos> factory = new POC_TEST_TIPOS_FactoryEntity();
            string storedProcedureName = "TBL_POC_TEST_TIPOS.TBL_POC_TEST_TIPOS_FBY_PK";
            using (DataContext dc = DataContext.CreateFromConnectionKey(KeyCadenaConexionPES))
            {
                t = 
                    dc.GetCommand(storedProcedureName).
                    AddParameter(id).
                    AddCursorParameter().
                    ExecuteReader(factory);
            }

thanks in advance...