//internal void Insert(Modulo parent)
        //{
        //    // if we're not dirty then don't update the database
        //    if (!this.IsDirty) return;

        //    //Debe obtener la sesion del padre pq el objeto es padre a su vez
        //    SessionCode = parent.SessionCode;

        //    _oid_modulo = parent.Oid;

        //    try
        //    {
        //        ValidationRules.CheckRules();

        //        if (!IsValid)
        //            throw new iQValidationException(moleQule.Library.Resources.Messages.GENERIC_VALIDATION_ERROR);

        //        parent.Session().Save(this);

        //        _preguntas.Update(this);
        //    }
        //    catch (Exception ex)
        //    {
        //        iQExceptionHandler.TreatException(ex);
        //    }

        //    MarkOld();
        //}

        //internal void Update(Modulo parent)
        //{
        //    // if we're not dirty then don't update the database
        //    if (!this.IsDirty) return;

        //    //Debe obtener la sesion del padre pq el objeto es padre a su vez
        //    SessionCode = parent.SessionCode;

        //    _oid_modulo = parent.Oid;

        //    try
        //    {
        //        ValidationRules.CheckRules();

        //        if (!IsValid)
        //            throw new iQValidationException(moleQule.Library.Resources.Messages.GENERIC_VALIDATION_ERROR);

        //        PlantillaExamen obj = parent.Session().Get<PlantillaExamen>(Oid);
        //        obj.CopyValues(this);
        //        parent.Session().Update(obj);

        //        _preguntas.Update(this);
        //    }
        //    catch (Exception ex)
        //    {
        //        iQExceptionHandler.TreatException(ex);
        //    }

        //    MarkOld();
        //}


        //internal void DeleteSelf(Modulo parent)
        //{
        //    // if we're not dirty then don't update the database
        //    if (!this.IsDirty) return;

        //    // if we're new then don't update the database
        //    if (this.IsNew) return;

        //    try
        //    {
        //        SessionCode = parent.SessionCode;
        //        Session().Delete(Session().Get<PlantillaExamen>(Oid));
        //    }
        //    catch (Exception ex)
        //    {
        //        iQExceptionHandler.TreatException(ex);
        //    }

        //    MarkNew();
        //}


        #endregion

        #region Root Data Access

        // called to retrieve data from the database
        private void DataPortal_Fetch(CriteriaEx criteria)
        {
            try
            {
                SessionCode = criteria.SessionCode;

                Childs = criteria.Childs;

                if (nHMng.UseDirectSQL)
                {
                    PlantillaExamen.DoLOCK(Session());
                    IDataReader reader = nHMng.SQLNativeSelect(criteria.Query, Session());

                    if (reader.Read())
                    {
                        _base.CopyValues(reader);
                    }

                    if (Childs)
                    {
                        string query;

                        Preguntas_Plantilla.DoLOCK(Session());
                        query      = Preguntas_Plantillas.SELECT_BY_PLANTILLA(this.Oid);
                        reader     = nHManager.Instance.SQLNativeSelect(query, Session());
                        _preguntas = Preguntas_Plantillas.GetChildList(reader);
                    }
                }
                else
                {
                    _base.Record.CopyValues((PlantillaExamenRecord)(criteria.UniqueResult()));

                    //Session().Lock(Session().Get<PlantillaExamen>(Oid), LockMode.UpgradeNoWait);

                    if (Childs)
                    {
                        criteria = Preguntas_Plantilla.GetCriteria(Session());
                        criteria.AddEq("OidPlantilla", this.Oid);
                        _preguntas = Preguntas_Plantillas.GetChildList(criteria.List <Preguntas_Plantilla>());
                    }
                }
            }
            catch (NHibernate.ADOException)
            {
                if (Transaction() != null)
                {
                    Transaction().Rollback();
                }
                throw new iQLockException(moleQule.Library.Resources.Messages.LOCK_ERROR);
            }
            catch (Exception ex)
            {
                if (Transaction() != null)
                {
                    Transaction().Rollback();
                }
                iQExceptionHandler.TreatException(ex);
            }
        }
        private void DataPortal_Create(CriteriaCs criteria)
        {
            Random r = new Random();

            Oid        = (long)r.Next();
            Codigo     = (0).ToString(Resources.Defaults.PLANTILLA_CODE_FORMAT);
            _preguntas = Preguntas_Plantillas.NewChildList();
        }
        /// <summary>
        /// Retrieve the complete list from db
        /// </summary>
        /// <returns>PreguntaList</returns>
        public static Preguntas_PlantillaList GetDisponiblesList(long oid_plantilla, DateTime fecha_disponibilidad)
        {
            CriteriaEx criteria = Preguntas_Plantilla.GetCriteria(Preguntas_Plantilla.OpenSession());

            criteria.Childs = false;
            criteria.Query  = Preguntas_Plantillas.SELECT_DISPONIBLES(oid_plantilla, fecha_disponibilidad);
            //No criteria. Retrieve all de List
            Preguntas_PlantillaList list = DataPortal.Fetch <Preguntas_PlantillaList>(criteria);

            CloseSession(criteria.SessionCode);

            return(list);
        }
        private void Fetch(PlantillaExamen source)
        {
            try
            {
                SessionCode = source.SessionCode;

                _base.CopyValues(source);

                CriteriaEx criteria;

                criteria = Preguntas_Plantilla.GetCriteria(Session());
                criteria.AddEq("OidPlantilla", this.Oid);
                _preguntas = Preguntas_Plantillas.GetChildList(criteria.List <Preguntas_Plantilla>());
            }
            catch (Exception ex)
            {
                iQExceptionHandler.TreatException(ex);
            }

            MarkOld();
        }
        private void Fetch(int session_code, IDataReader source)
        {
            try
            {
                _base.CopyValues(source);

                if (Childs)
                {
                    string query;

                    Preguntas_Plantilla.DoLOCK(Session(session_code));

                    query = Preguntas_Plantillas.SELECT_BY_PLANTILLA(this.Oid);
                    IDataReader reader = nHManager.Instance.SQLNativeSelect(query, Session(session_code));
                    _preguntas = Preguntas_Plantillas.GetChildList(reader);
                }
            }
            catch (Exception ex)
            {
                iQExceptionHandler.TreatException(ex);
            }

            MarkOld();
        }