/// <summary> /// Insert /// </summary> public PM_ALT_NOTI Insert(PM_ALT_NOTI entity) { ArgumentValidator.CheckForNullArgument(entity, "entity"); PersistentPM_ALT_NOTI PM_ALT_NOTIEntity = entity as PersistentPM_ALT_NOTI; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_NOTIDAO.SqlInsert); db.AddInParameter(dbCommand, "@NotiGuid", DbType.Guid, PM_ALT_NOTIEntity.NotiGuid); db.AddInParameter(dbCommand, "@AlertID", DbType.Guid, PM_ALT_NOTIEntity.AlertID); db.AddInParameter(dbCommand, "@UserGuid", DbType.Guid, PM_ALT_NOTIEntity.UserGuid); db.AddInParameter(dbCommand, "@DepartmentGuid", DbType.Guid, PM_ALT_NOTIEntity.DepartmentGuid); db.AddInParameter(dbCommand, "@AgentGuid", DbType.Guid, PM_ALT_NOTIEntity.AgentGuid); db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, PM_ALT_NOTIEntity.CreatedBy); db.AddInParameter(dbCommand, "@CreatedOn", DbType.DateTime, PM_ALT_NOTIEntity.CreatedOn); db.AddInParameter(dbCommand, "@UpdatedBy", DbType.String, PM_ALT_NOTIEntity.UpdatedBy); db.AddInParameter(dbCommand, "@UpdatedOn", DbType.DateTime, PM_ALT_NOTIEntity.UpdatedOn); int result = db.ExecuteNonQuery(dbCommand); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } return(PM_ALT_NOTIEntity as PM_ALT_NOTI); }
private void UpdateSome(PM_ALT_NOTI entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPM_ALT_NOTI PM_ALT_NOTIEntity = entity as PersistentPM_ALT_NOTI; StringBuilder sqlUpdateSome = new StringBuilder(); sqlUpdateSome.Append("UPDATE dbo.PM_ALT_NOTI SET "); PropertyInfo[] propertyInfos = PM_ALT_NOTIEntity.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_NOTIEntity, null); ORProperty property = EntityMapping[propertyInfo.Name]; if (!property.IsPrimaryKey) { if (!PM_ALT_NOTIEntity.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 NotiGuid = @NotiGuid "); 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); } }