C# 如果列和行是动态的,如何写入列表?

C# 如果列和行是动态的,如何写入列表?,c#,sql-server,C#,Sql Server,我从ms sql数据库中动态读取一些数据。Im将部门列表(行作为列标题)作为列,并将其相应的名称作为行。我使用下面的代码将其绑定到类文件列表 String @querystring="...."; IEnumerable<EmpDepartment> empdepartment = DB.ExecuteQuery<EmpDepartment>(@querystring).ToList(); foreach (EmpDepartment e

我从ms sql数据库中动态读取一些数据。Im将部门列表(行作为列标题)作为列,并将其相应的名称作为行。我使用下面的代码将其绑定到类文件列表

    String @querystring="....";
    IEnumerable<EmpDepartment> empdepartment = DB.ExecuteQuery<EmpDepartment>(@querystring).ToList();

        foreach (EmpDepartment empvar in empdepartment)
        {
            string Designame = empvar.Designation[0].DesignationName.ToString(); ---> Here it gives null             
        }
String@querystring=“…”;
IEnumerable empdepartment=DB.ExecuteQuery(@querystring.ToList();
foreach(EMP部门empvar在EMP部门)
{
字符串Designame=empvar.Designation[0]。DesignationName.ToString();-->这里它给出null
}
//我的班级看起来是这样的

public class Designationlist
{       
    public int DesignationId{ get; set; }
    public int DesignationName{ get; set; }
}

public class EmpDepartment
{
    public string DepartmentName{ get; set; }
    public IList<Designationlist> Designation{ get; set; }
}
公共类指定列表
{       
公共int指定ID{get;set;}
公共int指定名称{get;set;}
}
公营部门
{
公共字符串DepartmentName{get;set;}
公共IList名称{get;set;}
}
如果列及其对应行是动态的,如何写入列表

It should be of Designation,since designation of type Designationlist under EmpDepartment

foreach (EmpDepartment empvar in empdepartment)
{
    string Designame = empvar.Designation[0].DesignationName.ToString(); 
}