Anyname Donotcare
Anyname Donotcare

Reputation: 11393

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")

Upvotes: 1

Views: 1141

Answers (1)

Zbigniew
Zbigniew

Reputation: 27584

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();

Upvotes: 5

Related Questions