という名前のエンティティと、という名前AlertRuleEntity
のエンティティがありOccuredEventEntity
ます。1 つのアラートの下に複数のイベントを含めることができます。アラートとルールの関係は 1 対多であることを意味します。
これは私のエンティティがどのように見えるかです
public class AlertRuleEntity
{
public List<OccuredEventEntity> OccuredEventEntityList { get; set; }
public int AlertId { get; set; }
public int RuleId { get; set; }
public string RuleName { get; set; }
public string RuleType { get; set; }
public string Description { get; set; }
public string OccuredEventIds { get; set; }
public string UserName { get; set; }
public string AppName { get; set; }
public string AppType { get; set; }
public string AppTypeParameter { get; set; }
public string Penalty { get; set; }
public string RuleDate { get; set; }
}
public class OccuredEventEntity
{
public int OccuredEventId { get; set; }
public int EventId { get; set; }
public string EventName { get; set; }
public string EventType { get; set; }
public string Description { get; set; }
}
これは私の C# DAAB メソッドの一部です
m_DbCommand = new MySqlCommand("GetAlertRuleDetails;", m_DbConnection);
m_DbCommand.Parameters.Add(new MySqlParameter("alertId", alertId));
m_DbCommand.CommandType = System.Data.CommandType.StoredProcedure;
dtAlertRuleEntityList = ExecuteReader(m_DbCommand);
if (dtAlertRuleEntityList != null)
{
if (dtAlertRuleEntityList.Rows.Count > 0)
{
for (int index = 0; index < dtAlertRuleEntityList.Rows.Count; index++)
{
alertRuleEntity = new AlertRuleEntity();
if (dtAlertRuleEntityList.Rows[index]["AlertId"] != null && !dtAlertRuleEntityList.Rows[index]["AlertId"].Equals(DBNull.Value))
alertRuleEntity.AlertId = Convert.ToInt32(dtAlertRuleEntityList.Rows[index]["AlertId"]);
if (dtAlertRuleEntityList.Rows[index]["RuleId"] != null && !dtAlertRuleEntityList.Rows[index]["RuleId"].Equals(DBNull.Value))
alertRuleEntity.RuleId = Convert.ToInt32(dtAlertRuleEntityList.Rows[index]["RuleId"]);
if (dtAlertRuleEntityList.Rows[index]["RuleName"] != null && !dtAlertRuleEntityList.Rows[index]["RuleName"].Equals(DBNull.Value))
alertRuleEntity.RuleName = Convert.ToString(dtAlertRuleEntityList.Rows[index]["RuleName"]);
if (dtAlertRuleEntityList.Rows[index]["RuleType"] != null && !dtAlertRuleEntityList.Rows[index]["RuleType"].Equals(DBNull.Value))
alertRuleEntity.RuleType = Convert.ToString(dtAlertRuleEntityList.Rows[index]["RuleType"]);
if (dtAlertRuleEntityList.Rows[index]["Description"] != null && !dtAlertRuleEntityList.Rows[index]["Description"].Equals(DBNull.Value))
alertRuleEntity.Description = Convert.ToString(dtAlertRuleEntityList.Rows[index]["Description"]);
if (dtAlertRuleEntityList.Rows[index]["OccuredEventIds"] != null && !dtAlertRuleEntityList.Rows[index]["OccuredEventIds"].Equals(DBNull.Value))
alertRuleEntity.OccuredEventIds = Convert.ToString(dtAlertRuleEntityList.Rows[index]["OccuredEventIds"]);
if (dtAlertRuleEntityList.Rows[index]["OccuredEventIds"] != null && !dtAlertRuleEntityList.Rows[index]["OccuredEventIds"].Equals(DBNull.Value))
alertRuleEntity.OccuredEventEntityList = GetOccuredEventDetails(alertRuleEntity.OccuredEventIds);
if (dtAlertRuleEntityList.Rows[index]["UserName"] != null && !dtAlertRuleEntityList.Rows[index]["UserName"].Equals(DBNull.Value))
alertRuleEntity.UserName = Convert.ToString(dtAlertRuleEntityList.Rows[index]["UserName"]);
if (dtAlertRuleEntityList.Rows[index]["AppName"] != null && !dtAlertRuleEntityList.Rows[index]["AppName"].Equals(DBNull.Value))
alertRuleEntity.AppName = Convert.ToString(dtAlertRuleEntityList.Rows[index]["AppName"]);
if (dtAlertRuleEntityList.Rows[index]["AppType"] != null && !dtAlertRuleEntityList.Rows[index]["AppType"].Equals(DBNull.Value))
alertRuleEntity.AppType = Convert.ToString(dtAlertRuleEntityList.Rows[index]["AppType"]);
if (dtAlertRuleEntityList.Rows[index]["AppTypeParameter"] != null && !dtAlertRuleEntityList.Rows[index]["AppTypeParameter"].Equals(DBNull.Value))
alertRuleEntity.AppTypeParameter = Convert.ToString(dtAlertRuleEntityList.Rows[index]["AppTypeParameter"]);
if (dtAlertRuleEntityList.Rows[index]["Penalty"] != null && !dtAlertRuleEntityList.Rows[index]["Penalty"].Equals(DBNull.Value))
alertRuleEntity.Penalty = Convert.ToString(dtAlertRuleEntityList.Rows[index]["Penalty"]);
if (dtAlertRuleEntityList.Rows[index]["RuleDate"] != null && !dtAlertRuleEntityList.Rows[index]["RuleDate"].Equals(DBNull.Value))
alertRuleEntity.RuleDate = String.Format("{0:MM/dd/yyyy HH:mm:ss}", dtAlertRuleEntityList.Rows[index]["RuleDate"]);
alertRuleEntityList.Add(alertRuleEntity);
}
}
}
今日まで、結果を得るために2つの手順を使用しました。
GetAlertRuleDetails(IN alertId INT(11))
GetOccuredEventDetails(IN occuredEventIds VARCHAR(255))
ここで、単一のプロシージャ コールのみから実行する必要があります。新しい手順を作成しました。このプロシージャは、ルールのエントリとそれぞれのイベントを同時に返します。
この新しい手順の結果から初期化する適切な方法は何ですかOccuredEventEntityList
?AlertRuleEntity