我有一個查詢,我努力轉換爲LINQ。我無法滿足所需的嵌套。下面是SQL查詢(只是寫意鍵入):SQL到LINQ JOIN和子查詢
SELECT V.* FROM V
INNER JOIN VE ON V.ID = VE.V_ID
WHERE VE.USER_ID != @USER_ID
AND V.MAX > (SELECT COUNT(ID) FROM VE
WHERE VE.V_ID = V.ID AND VE.STATUS = 'SELECTED')
的最近我來是這樣的:
var query = from vac in _database.Vacancies
join e in _database.VacancyEngagements
on vac.Id equals e.VacancyId into va
from v in va.DefaultIfEmpty()
where vac.MaxRecruiters > (from ve in _database.VacancyEngagements
where ve.VacancyId == v.Id && ve.Status == Enums.VacanyEngagementStatus.ENGAGED
select ve).Count()
...它正確地從我的SQL語句解析子查詢。但是我想進一步限制返回的V行到只有當前用戶沒有相關VE行的行。
您可以在'into'關鍵字之前放置'where e.UserId!= userId'。 –
@GertArnold,這會導致語法錯誤:「查詢正文必須以select子句或group子句結尾」 – sfkHooper
您的查詢在最後已經缺少「select」。 –