c# - Simple Example Subquery Linq -
t-sql query
select * dbo.user_users userid in (select userid course_enrollments)
linq entities alternative of above query
var innerquery = en in course_enrollments select en.userid; var query = u in user_users innerquery.contains(u.userid) select u;
there alot of complex subqueries on stackoverflow, want see simple example of how simple subquery done via linq.this how done it, not because sends 2 queries database.
simple answer use "let" keyword , generate sub-query supports conditional set main entity.
var usersenrolledincourses = u in user_users let ces = ce in course_enrollments select ce.userid ces.contains(u.userid) select u;
this create exists block in tsql similar to
select [extent1].* dbo.user_users extent1 exists (select 1 [c1] dbo.course_enrollements extent2 (extent2.userid = extent1.userid))
it's close you've asked , create same query plan on sql server.
hope helps!
Comments
Post a Comment