1 回答

TA貢獻1805條經(jīng)驗 獲得超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;}
}
因此,應(yīng)用映射后,您的代碼將如下所示:
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 關(guān)注
- 169 瀏覽
添加回答
舉報