SQL Query使用不存在和连接的LINQ语法

我的SQL查询就像下面在SQL中工作正常我需要将其转换为LINQ语法

SQL-

SELECT [Key], Id
FROM LocalizationKeys AS lk
WHERE NOT EXISTS (SELECT 1
                  FROM Languages AS l
                  JOIN LocalizationValues AS lv ON l.Id = lv.LanguageId
                  WHERE l.Title = 'en-US' AND lv.LocalizationKeyId = lk.Id)

LINQ语法我试过了

var result = 

(from lk in localizationKey    
where !(from l in lang
        join lv in localizationValue on l.Id equals lv.LanguageId
        where l.Title == "en-US" && lv.LocalizationKeyId == lk.Id select 1).FirstOrDefault()   

 select lk).ToList();

出错:

操作员'!' 不能应用于'int'类型的操作数

任何线索我犯了错误?


你可以尝试这样的:

(from lk in localizationKey    
where (from l in lang
        join lv in localizationValue on l.Id equals lv.LanguageId
        where (l.Title == "en-US" && lv.LocalizationKeyId == lk.Id)   
       select l).FirstOrDefault() == null
 select lk).ToList();

要么

(from lk in localizationKey    
where !(from l in lang
        join lv in localizationValue on l.Id equals lv.LanguageId
        where !(l.Title == "en-US" && lv.LocalizationKeyId == lk.Id) 
        select l).FirstOrDefault().Any()
 select lk).ToList();

尝试这个:

(from lk in localizationKey    
where (from l in lang
        join lv in localizationValue on l.Id equals lv.LanguageId
        where !(l.Title == "en-US" && lv.LocalizationKeyId == lk.Id) select 1).FirstOrDefault()   

 select lk).ToList();

我认为你原来的查询很好,你只需要在where子句中添加另一对括号:

(from lk in localizationKey     
  where !((from l in lang
        join lv in localizationValue on l.Id equals lv.LanguageId
        where l.Title == "en-US" && lv.LocalizationKeyId == lk.Id select 1).Any())
 select lk).ToList();
链接地址: http://www.djcxy.com/p/32993.html

上一篇: SQL Query to LINQ syntax using not exist and join

下一篇: Read Amibroker price volume data using python