I have an employee table containing a list of employees. Each mployee have an ID, a corporate ID, COR_N_ID and a mother, MOTHER. The MOTHER field is actually the ID of another employee. Some employees have another Employee attached to them and in this case, the MOTHER field is filled. Else it is left as null. Employees can have a list of employees attached to them and some have none.
I have an SQL request to get a list of employees having no attached employees:
select *
from Employee a
where COR_N_ID = 99
and (select count(ID) from Employee b where b.MOTHER = a.ID) = 0;
However, I am stuck at converting this to linQ. What I have done so far:
var query = (from emp in Employee.FindAll(item => (
item.COR_N_ID == id
))
select new KeyValuePair
{
Key = business.Id.ToString(),
Value = business.CBA_CH_NAME
}
);
Any help please?
I think we can remove the COR_N_ID condition here.
I just want a list of all employees having no other employees attached to them. Note that the field linking an employee to another one is the MOTHER field.
I have tried this:
var query = (from emp in Employee.FindAll(item => (
item.COR_N_ID == id
))
.where(item2 => !Employee.FindAll(item => item.MOTHER == business.ID))
select new KeyValuePair
{
Key = business.Id.ToString(),
Value = business.CBA_CH_NAME
}
);
But this does not work.
I have this:
But I want this: