C# 正在初始化实体列表成员,该成员是过程结果中一个实体的一部分

C# 正在初始化实体列表成员,该成员是过程结果中一个实体的一部分,c#,mysql,.net,ado.net,C#,Mysql,.net,Ado.net,我有一个名为AlertRuleEntity的实体,另一个名为occurrendecontentity。一个警报下可以有多个事件。表示警报和规则之间的关系是一对多 这就是我的实体的样子 public class AlertRuleEntity { public List<OccuredEventEntity> OccuredEventEntityList { get; set; } public int AlertId { get; set; } public

我有一个名为
AlertRuleEntity
的实体,另一个名为
occurrendecontentity
。一个警报下可以有多个事件。表示警报和规则之间的关系是一对多

这就是我的实体的样子

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; }
}
现在我只需要从一个过程调用开始。我创建了新的程序。此过程将同时返回规则条目和相应事件

根据此新过程的结果初始化
AlertRuleEntity
OccurdeEventyList
的正确方法是什么

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))