Ejemplo n.º 1
0
        public EntityRepository ExecuteSql(DataService Service, int CommandTimeout)
        {
            return((EntityRepository)Execute(Service, (DbConnection, DbCommand) =>
            {
                String sql = DbCommand.CommandText;

                Service.Parameters.ForEach((parameter) =>
                {
                    sql = sql.Replace("{" + parameter.Name + "}", parameter.Value.ToString());
                });
                DbCommand.CommandText = sql;


                DbCommand.CommandType = System.Data.CommandType.Text;

                System.Data.IDbDataAdapter adapter = (System.Data.Common.DbDataAdapter)Activator.CreateInstance(typeof(TAdapter));

                System.Data.DataSet ds = new System.Data.DataSet();
                adapter.SelectCommand = DbCommand;
                adapter.Fill(ds);
                EntityRepository Repository = new EntityRepository(ds);

                return Repository;
            }, CommandTimeout));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Ejecuta una accion contra la DB y devuelve el resultado de esta bajo un esquema de repositorio (configuracion a traves del Services.xml)
        /// </summary>
        /// <param name="Service">Servicio de Datos</param>
        /// <param name="CommandTimeout">Tiempo de espera para que la ejecucion retorne la respuesta</param>
        /// <returns>Repositorio de entidades</returns>
        public EntityRepository ExecuteQuery(DataService Service, Int32 CommandTimeout)
        {
            return((EntityRepository)Execute(Service, (DbConnection, DbCommand) =>
            {
                System.Data.IDbDataAdapter adapter = (System.Data.Common.DbDataAdapter)Activator.CreateInstance(typeof(TAdapter));

                System.Data.DataSet ds = new System.Data.DataSet();
                adapter.SelectCommand = DbCommand;
                adapter.Fill(ds);
                EntityRepository Repository = new EntityRepository(ds);

                return Repository;
            }, CommandTimeout));
        }
Ejemplo n.º 3
0
        public static System.Data.IDataAdapter DataAdapterFactory(string engineName, System.Data.IDbCommand cmd)
        {
            ConnectorConstants.ConnectorEngineEnum engine = FindEngine(engineName);
            Type retour = null;

            if (engine == ConnectorConstants.ConnectorEngineEnum.MSSQL)
            {
                retour = Nglib.APP.CODE.ReflectionTools.GetTypeByReflexion("System.Data.SqlClient.SqlDataAdapter, System.Data");
                if (retour == null)
                {
                    retour = Nglib.APP.CODE.ReflectionTools.GetTypeByReflexion("System.Data.SqlClient.SqlDataAdapter, System.Data.SqlClient");
                }
            }
            else if (engine == ConnectorConstants.ConnectorEngineEnum.POSTGRESQL)
            {
                retour = Nglib.APP.CODE.ReflectionTools.GetTypeByReflexion("Npgsql.NpgsqlDataAdapter, Npgsql");
            }
            else if (engine == ConnectorConstants.ConnectorEngineEnum.SQLITE)
            {
                retour = Nglib.APP.CODE.ReflectionTools.GetTypeByReflexion("System.Data.SQLite.SQLiteDataAdapter, System.Data.SQLite");
            }
            else if (engine == ConnectorConstants.ConnectorEngineEnum.ORACLE)
            {
                retour = Nglib.APP.CODE.ReflectionTools.GetTypeByReflexion("System.Data.OracleClient.OracleDataAdapter, System.Data.OracleClient");
            }
            else if (engine == ConnectorConstants.ConnectorEngineEnum.ACCESS)
            {
                retour = Nglib.APP.CODE.ReflectionTools.GetTypeByReflexion("System.Data.OleDb.OleDbDataAdapter, System.Data");
                if (retour == null)
                {
                    retour = Nglib.APP.CODE.ReflectionTools.GetTypeByReflexion("System.Data.OleDb.OleDbDataAdapter, System.Data.OleDb");
                }
                if (retour == null)
                {
                    retour = Nglib.APP.CODE.ReflectionTools.GetTypeByReflexion("System.Data.OleDb.OleDbDataAdapter, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");                 // !!!
                }
            }

            if (retour == null)
            {
                throw new Exception(string.Format("Engine/DLL IDataAdapter for {0} not found. Please include DLL for this engine in your project", engineName));
            }

            System.Data.IDbDataAdapter val = Nglib.APP.CODE.ReflectionTools.NewInstance <System.Data.IDbDataAdapter>(retour);
            val.SelectCommand = cmd;
            return(val);
        }