如何在linq查询中选择动态列

时间:2017-11-27 09:05:29

标签: asp.net-mvc entity-framework linq

public class EmployeerRequest
{
    public long EmployeeRequestID { get; set; }
    public long EmployeePolicyID { get; set; }
    public string EmployeeSrNo { get; set; }
    public string EmployeeSequenceNo { get; set; }
}

List<EmployeerRequest> empRequestList = new List<EmployeerRequest>();

var r = empRequestList.Select(x => new
{ 
    EmployeeRequestID = x.EmployeeRequestID,
    EmployeePolicyID = x.EmployeePolicyID
});

var r = empRequestList.Select(x => new
{ 
    EmployeePolicyID = x.EmployeePolicyID,
    EmployeeSrNo = x.EmployeeSrNo
});

var r = empRequestList.Select(x => new
{ 
    EmployeeSequenceNo = x.EmployeeSequenceNo
});

我想在linq中选择动态列,如上所述,具体取决于参数中传递的列参数。如何给动态选择?

0 个答案:

没有答案