简体   繁体   中英

How to select multiple fields (LINQ)

How to change the following linq query to select another field value Field<int>("data_entry") ,i want to select multiple fields .


 var a = DF_Utilities.GetAvailableTasks(empnum, 1).AsEnumerable().Where(
    p => p.Field<int>("task_code") == int.Parse(drpTasks.SelectedValue)).Select(p => p.Field<int>("cand_num")).First();

p.Field<int>("cand_num"),Field<int>("data_entry")

instead of p.Field<int>("cand_num")

You can use anonymous type :

var a = DF_Utilities.
    GetAvailableTasks(empnum, 1).
    AsEnumerable().
    Where(p => p.Field<int>("task_code") == int.Parse(drpTasks.SelectedValue)).
    Select(p => new 
    {
        candNum = p.Field<int>("cand_num"),
        dataEntry = p.Field<int>("data_entry")
    }).
    First();

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