Extract single column from var using linq

I have something like this

var emp = db.Employees.toList();

in the table of my employees I have the name emp, emp id and salary, using linq with lambda expressions, how can I access emp id in another variable. I tried to find it, could not find a solution that does this with linq with lambda expressions

var employeeLeaves = db.Leaves
     .Include("Employee")
     .Include("Employee.Manager")
     .Where(l => l.Status.Id == 1)
     .GroupBy(l => l.Employee.Manager.Id)
     .Select(l => l.GroupBy(k=>k.Employee.Id).Select(j=>j.GroupBy(โ€Œโ€‹p=>p.GroupId)))
     .ToList(); 

this is the actual query that I have, donโ€™t ask me how I wrote it ..: P now I want to get the id column from employeeLeaves and save it in another variable

+3
source share
5 answers

, , . " " " ", - :

var ids = emp.Select(x => x.Id);

:

var ids = db.Employees.Select(x => x.Id);

( ToList .)

LINQ ( , var), , . , , - , , , IMO.

+9
var empId = db.Employees.Single(x => x.id == 5).Id;
+2

Try this syntax:

var empIds = db.Employees.Select(e=>e.EmpID)
0
source

You can use select. Maybe something like this:

var result=db.Employees
              .Select(s=>s.emp_id);
0
source
Database.Tablename.Single(x => x.id == anyId)

This should select one line

0
source

All Articles