private void UpdateAll(PM_ALT_ELEMENT entity)
        {
            ArgumentValidator.CheckForNullArgument(entity, "entity");

            PersistentPM_ALT_ELEMENT PM_ALT_ELEMENTEntity = entity as PersistentPM_ALT_ELEMENT;

            try
            {
                Database  db        = GetDatabaseInstance();
                DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_ELEMENTDAO.SqlUpdate);

                db.AddInParameter(dbCommand, "@ElementID", DbType.Guid, PM_ALT_ELEMENTEntity.ElementID);
                db.AddInParameter(dbCommand, "@AlertID", DbType.Guid, PM_ALT_ELEMENTEntity.AlertID);
                db.AddInParameter(dbCommand, "@ElementField", DbType.String, PM_ALT_ELEMENTEntity.ElementField);
                db.AddInParameter(dbCommand, "@ElementAlias", DbType.String, PM_ALT_ELEMENTEntity.ElementAlias);
                db.AddInParameter(dbCommand, "@ElementType", DbType.String, PM_ALT_ELEMENTEntity.ElementType);
                db.AddInParameter(dbCommand, "@Sequence", DbType.Int32, PM_ALT_ELEMENTEntity.Sequence);
                db.AddInParameter(dbCommand, "@IsActive", DbType.Boolean, PM_ALT_ELEMENTEntity.IsActive);
                db.AddInParameter(dbCommand, "@RowDeleted", DbType.Boolean, PM_ALT_ELEMENTEntity.RowDeleted);
                db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, PM_ALT_ELEMENTEntity.CreatedBy);
                db.AddInParameter(dbCommand, "@CreatedOn", DbType.DateTime, PM_ALT_ELEMENTEntity.CreatedOn);
                db.AddInParameter(dbCommand, "@ModifiedBy", DbType.String, PM_ALT_ELEMENTEntity.ModifiedBy);
                db.AddInParameter(dbCommand, "@ModifiedOn", DbType.DateTime, PM_ALT_ELEMENTEntity.ModifiedOn);
                int result = db.ExecuteNonQuery(dbCommand);

                if (result == 0)
                {
                    throw new EntityNotFoundException();
                }
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy);
            }
        }
 //
 public void SaveBatch(Guid alertID, IList <PM_ALT_ELEMENT> entities, out string returnMessage)
 {
     returnMessage = string.Empty;
     //
     try
     {
         //1.
         _PM_ALT_ELEMENTDAO.SetDeletedByAlert(alertID);
         //2.
         foreach (PM_ALT_ELEMENT entity in entities)
         {
             PM_ALT_ELEMENT entityExisted = this.GetEntity(entity.ElementID.Value);
             if (null == entityExisted)
             {
                 this.Insert(entity);
             }
             else
             {
                 entity.RowDeleted = false;
                 this.UpdateSome(entity);
             }
         }
         //3.
         _PM_ALT_ELEMENTDAO.ClearDeletedByAlert(alertID);
     }
     catch (Exception ex)
     {
         returnMessage = ex.Message;
         return;
     }
 }
        /// <summary>
        /// Get with transaction
        /// </summary>
        public PM_ALT_ELEMENT Get(object entityId, DbTransaction transaction)
        {
            ArgumentValidator.CheckForNullArgument(entityId, "entityId");
            ArgumentValidator.CheckForNullArgument(transaction, "transaction");

            PM_ALT_ELEMENT PM_ALT_ELEMENTEntity = null;

            try
            {
                Database  db        = GetDatabaseInstance();
                DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_ELEMENTDAO.SqlGet);

                db.AddInParameter(dbCommand, "@ElementID", DbType.Guid, entityId);
                using (IDataReader dataReader = db.ExecuteReader(dbCommand, transaction))
                {
                    if (dataReader.Read())
                    {
                        PM_ALT_ELEMENTEntity = ReadEntity(dataReader);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy);
            }

            return(PM_ALT_ELEMENTEntity);
        }
        /// <summary>
        /// Insert with transaction
        /// </summary>
        public PM_ALT_ELEMENT Insert(PM_ALT_ELEMENT entity, DbTransaction transaction)
        {
            ArgumentValidator.CheckForNullArgument(entity, "entity");
            ArgumentValidator.CheckForNullArgument(transaction, "transaction");
            PersistentPM_ALT_ELEMENT PM_ALT_ELEMENTEntity = entity as PersistentPM_ALT_ELEMENT;

            try
            {
                Database  db        = GetDatabaseInstance();
                DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_ELEMENTDAO.SqlInsert);

                db.AddInParameter(dbCommand, "@ElementID", DbType.Guid, PM_ALT_ELEMENTEntity.ElementID);
                db.AddInParameter(dbCommand, "@AlertID", DbType.Guid, PM_ALT_ELEMENTEntity.AlertID);
                db.AddInParameter(dbCommand, "@ElementField", DbType.String, PM_ALT_ELEMENTEntity.ElementField);
                db.AddInParameter(dbCommand, "@ElementAlias", DbType.String, PM_ALT_ELEMENTEntity.ElementAlias);
                db.AddInParameter(dbCommand, "@ElementType", DbType.String, PM_ALT_ELEMENTEntity.ElementType);
                db.AddInParameter(dbCommand, "@Sequence", DbType.Int32, PM_ALT_ELEMENTEntity.Sequence);
                db.AddInParameter(dbCommand, "@IsActive", DbType.Boolean, PM_ALT_ELEMENTEntity.IsActive);
                db.AddInParameter(dbCommand, "@RowDeleted", DbType.Boolean, PM_ALT_ELEMENTEntity.RowDeleted);
                db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, PM_ALT_ELEMENTEntity.CreatedBy);
                db.AddInParameter(dbCommand, "@CreatedOn", DbType.DateTime, PM_ALT_ELEMENTEntity.CreatedOn);
                db.AddInParameter(dbCommand, "@ModifiedBy", DbType.String, PM_ALT_ELEMENTEntity.ModifiedBy);
                db.AddInParameter(dbCommand, "@ModifiedOn", DbType.DateTime, PM_ALT_ELEMENTEntity.ModifiedOn);

                int result = db.ExecuteNonQuery(dbCommand, transaction);
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy);
            }

            return(PM_ALT_ELEMENTEntity as PM_ALT_ELEMENT);
        }
 public void Update(PM_ALT_ELEMENT entity, bool updateAll, DbTransaction transaction)
 {
     if (!updateAll)
     {
         UpdateSome(entity, transaction);
     }
     else
     {
         UpdateAll(entity, transaction);
     }
 }
 public void Update(PM_ALT_ELEMENT entity, bool updateAll)
 {
     if (!updateAll)
     {
         UpdateSome(entity);
     }
     else
     {
         UpdateAll(entity);
     }
 }
        public void UpdateSome(PM_ALT_ELEMENT entity)
        {
            try
            {
                ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_ELEMENT Entity");

                _PM_ALT_ELEMENTDAO.Update(entity, false);
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy);
            }
        }
        //
        #region base interface impl

        public PM_ALT_ELEMENT Insert(PM_ALT_ELEMENT entity)
        {
            PM_ALT_ELEMENT newEntity = null;

            try
            {
                ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_ELEMENT Entity");

                newEntity = _PM_ALT_ELEMENTDAO.Insert(entity);
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy);
            }

            return(newEntity);
        }
        public PM_ALT_ELEMENT GetEntity(Guid entityGuid)
        {
            PM_ALT_ELEMENT entity = null;

            try
            {
                ArgumentValidator.CheckForNullArgument(entityGuid, "PM_ALT_ELEMENT Guid");

                entity = _PM_ALT_ELEMENTDAO.Get(entityGuid);
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy);
            }

            return(entity);
        }
        private static PM_ALT_ELEMENT ReadEntity(IDataReader dataReader)
        {
            PM_ALT_ELEMENT PM_ALT_ELEMENTEntity = new PM_ALT_ELEMENT();
            object         value;


            value = dataReader["ElementID"];
            if (value != DBNull.Value)
            {
                PM_ALT_ELEMENTEntity.ElementID = (Guid?)value;
            }

            value = dataReader["AlertID"];
            if (value != DBNull.Value)
            {
                PM_ALT_ELEMENTEntity.AlertID = (Guid?)value;
            }

            value = dataReader["ElementField"];
            if (value != DBNull.Value)
            {
                PM_ALT_ELEMENTEntity.ElementField = (String)value;
            }

            value = dataReader["ElementAlias"];
            if (value != DBNull.Value)
            {
                PM_ALT_ELEMENTEntity.ElementAlias = (String)value;
            }

            value = dataReader["ElementType"];
            if (value != DBNull.Value)
            {
                PM_ALT_ELEMENTEntity.ElementType = (String)value;
            }

            value = dataReader["Sequence"];
            if (value != DBNull.Value)
            {
                PM_ALT_ELEMENTEntity.Sequence = (Int32?)value;
            }

            value = dataReader["IsActive"];
            if (value != DBNull.Value)
            {
                PM_ALT_ELEMENTEntity.IsActive = (Boolean?)value;
            }

            value = dataReader["RowDeleted"];
            if (value != DBNull.Value)
            {
                PM_ALT_ELEMENTEntity.RowDeleted = (Boolean?)value;
            }

            value = dataReader["CreatedBy"];
            if (value != DBNull.Value)
            {
                PM_ALT_ELEMENTEntity.CreatedBy = (String)value;
            }

            value = dataReader["CreatedOn"];
            if (value != DBNull.Value)
            {
                PM_ALT_ELEMENTEntity.CreatedOn = (DateTime?)value;
            }

            value = dataReader["ModifiedBy"];
            if (value != DBNull.Value)
            {
                PM_ALT_ELEMENTEntity.ModifiedBy = (String)value;
            }

            value = dataReader["ModifiedOn"];
            if (value != DBNull.Value)
            {
                PM_ALT_ELEMENTEntity.ModifiedOn = (DateTime?)value;
            }

            return(PM_ALT_ELEMENTEntity);
        }
        private void UpdateSome(PM_ALT_ELEMENT entity, DbTransaction transaction)
        {
            ArgumentValidator.CheckForNullArgument(entity, "entity");
            ArgumentValidator.CheckForNullArgument(transaction, "transaction");

            PersistentPM_ALT_ELEMENT PM_ALT_ELEMENTEntity = entity as PersistentPM_ALT_ELEMENT;

            StringBuilder sqlUpdateSome = new StringBuilder();

            sqlUpdateSome.Append("UPDATE dbo.PM_ALT_ELEMENT SET ");

            PropertyInfo[] propertyInfos        = PM_ALT_ELEMENTEntity.GetType().GetProperties();
            Hashtable      propertyValues       = new System.Collections.Hashtable();
            int            columnCountForUpdate = 0;

            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                if (EntityMapping.ContainsProperty(propertyInfo.Name))
                {
                    object     propertyValue = propertyInfo.GetValue(PM_ALT_ELEMENTEntity, null);
                    ORProperty property      = EntityMapping[propertyInfo.Name];
                    if (!property.IsPrimaryKey)
                    {
                        if (!PM_ALT_ELEMENTEntity.IsDefaultValue(propertyInfo.Name))
                        {
                            propertyValues[propertyInfo.Name] = propertyValue;

                            sqlUpdateSome.Append(" " + property.ColumnName + " = @" + property.ColumnName + ",");
                            columnCountForUpdate++;
                        }
                    }
                    else
                    {
                        propertyValues[propertyInfo.Name] = propertyValue;
                    }
                }
            }
            if (columnCountForUpdate == 0)
            {
                return;
            }

            sqlUpdateSome.Remove(sqlUpdateSome.Length - 1, 1);
            sqlUpdateSome.Append(" WHERE 1 = 1 ");
            sqlUpdateSome.Append(" AND ElementID = @ElementID ");

            try
            {
                Database  db        = GetDatabaseInstance();
                DbCommand dbCommand = db.GetSqlStringCommand(sqlUpdateSome.ToString());

                foreach (DictionaryEntry de in propertyValues)
                {
                    ORProperty property = EntityMapping[de.Key.ToString()];
                    db.AddInParameter(dbCommand, "@" + property.ColumnName, property.DatabaseType, de.Value);
                }

                int result = db.ExecuteNonQuery(dbCommand, transaction);

                if (result == 0)
                {
                    throw new EntityNotFoundException();
                }
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy);
            }
        }
        /// <summary>
        /// Update with transaction
        /// </summary>

        public void Update(PM_ALT_ELEMENT entity, DbTransaction transaction)
        {
            Update(entity, true, transaction);
        }
        /// <summary>
        /// Update
        /// </summary>

        public void Update(PM_ALT_ELEMENT entity)
        {
            Update(entity, true);
        }