Helper for Enterprise Library version 4.1

Topics: Data Access Application Block
Oct 20, 2009 at 11:23 AM

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;
                }
            }
thanks in advance...

Oct 21, 2009 at 3:26 AM

Hi,

I'm not really sure what do you mean by that. Are you looking for Helper classes (that will reduce the said code) that comes from the Data Access Application Block? If that is what you mean, there is none. You would have to create your own helper classes.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 21, 2009 at 7:30 AM

Thanks.

For example, I do like this:

 <font size="2">

 

</font>

//PROCEDURE TBL_POC_TEST_TIPOS_FBY_PK(P_ID_TEST_TIPOS IN VARCHAR2, P_REFCURSOR OUT SYS_REFCURSOR);

 

 

//PROCEDURE TBL_POC_TEST_TIPOS_FBY_PK(P_ID_TEST_TIPOS IN VARCHAR2, P_REFCURSOR OUT SYS_REFCURSOR);
        public Entidades.Tipos FindByPK_ID_TESTHelper(string id)
        {
            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);
            }

            IBuilderFromDataReader factory2 = new POC_TEST_TIPOS_FactorySingle();
            using (DataContext dc2 = DataContext.CreateFromConnectionKey(KeyCadenaConexionPES))
            {
                factory2 =
                    dc2.GetCommand(storedProcedureName).
                    AddParameter(id).
                    AddCursorParameter().
                    ExecuteReader(factory2);

                t = ((POC_TEST_TIPOS_FactorySingle)factory2).Entity;
            }
            return t;

        }

Thanks in advanced. 

Oct 21, 2009 at 8:50 AM

You are trying to convert this code to daab code, is that right? On your initial post, is that the converted code? It looks fine, what is the problem with that?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com