0

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

    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             
        }

// 我的班级看起来像这样,

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; }
}

如果列及其对应的行是动态的,如何写入列表。

4

1 回答 1

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

foreach (EmpDepartment empvar in empdepartment)
{
    string Designame = empvar.Designation[0].DesignationName.ToString(); 
}
于 2012-12-26T11:49:05.143 回答