Linq to SQL Nested Query Where In

Contoh Linq to SQL nested query where in

[code language=”sql”]
select …
from x
where x in (select id from …)
[/code]

[code language=”csharp”]
IQueryable<int> innerQuery;

//algoritma
innerQuery =
from log in db.permit_log
where log.user_id == UserId && log.permit_type == 0 &&
(log.status == KPIMaster.SupervisorApprove || log.status == KPIMaster.SupervisorReject)
select log.id_permit.Value;

var query =
from permit in db.permit_log
where innerQuery.Distinct().Contains(permit.id_permit.Value) &&
permit.permit_type == 0 &&
(permit.status == KPIMaster.RequestorApprove || permit.status == KPIMaster.SupervisorReject ||
permit.status == KPIMaster.SupervisorApprove || permit.status == KPIMaster.AssessorReject ||
permit.status == KPIMaster.FOReject)
select permit
;
[/code]

Chandra Oemaryadi has written 244 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>