1 回答
TA贡献1805条经验 获得超10个赞
employee和的模式employee_details类似于:
public class employee
{
public string Name {get;set;}
public string Department {get;set;}
}
public class employee_details
{
public string Address {get;set;}
public string Mobile {get;set;}
}
因此,应用映射后,您的代码将如下所示:
var query = objEmployee.sp_display().Select(s=> new ViewModel{
employees = new employee{
Name = s.Name //change the s.Name to the property name coming from your SP(if different)
Department = s.Department
},
employee_detail = new employee_detail{
Address = s.Address,
Mobile = s.Mobile
}}).ToList()
或者最好删除该query对象并使用,listEmployeeList因为该列表本身也引用该对象,ViewModel因此该query对象是不必要的(除非您想对其进行其他一些过滤):
listEmployeeList = // the above code with .ToList();
- 1 回答
- 0 关注
- 135 浏览
添加回答
举报