简体   繁体   中英

How to get data from anonymous list in C#

I have anonymous type list. I want to get data from this list

My code is as bellow

 var data = from EP in DbContext.EmployeeProfesionalDtls
                       join DM in DbContext.DesignationMasters on EP.DesigId equals DM.DesigId
                       join DP in DbContext.DepartmentMasters on new { DepId = EP.DepId } equals new { DepId = DP.DeptId }
                       select new
                       {
                           ProfId = EP.ProfId,
                           EmpId = EP.EmpId,
                           EntryDate = DM.EntryDate,
                           DeptName = DP.DeptName,
                           DepartmentUnitID = DP.UnitId,
                           DepartmentEntryDate = DP.EntryDate
                       }

"data" have anonymous type list. I wants to get data from this anonymous type list.

You have to take a view model ie a class to send it to view :

var data = from EP in DbContext.EmployeeProfesionalDtls
                   join DM in DbContext.DesignationMasters on EP.DesigId equals DM.DesigId
                   join DP in DbContext.DepartmentMasters on new { DepId = EP.DepId } equals new { DepId = DP.DeptId }
                   select new Test()
                   {
                       ProfId = EP.ProfId,
                       EmpId = EP.EmpId,
                       EntryDate = DM.EntryDate,
                       DeptName = DP.DeptName,
                       DepartmentUnitID = DP.UnitId,
                       DepartmentEntryDate = DP.EntryDate
                   }

where Test is a class with these properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM