我有一个名为AlertRuleEntity
的实体和另一个名为OccuredEventEntity
的实体。一个警报可以在其下面有多个事件。意味着警报和规则之间的关系是一对多的。
这就是我的实体的样子
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);
}
}
}
到目前为止,我使用了两个程序来获得结果。
GetAlertRuleDetails(IN alertId INT(11))
GetOccuredEventDetails(IN occuredEventIds VARCHAR(255))
现在我需要从单程序调用中完成。我创建了新程序。此过程将同时返回规则和相应事件的条目。
从此新程序的结果中初始化OccuredEventEntityList
AlertRuleEntity
的正确方法是什么