gpt4 book ai didi

c# - 使用不存在和连接的 SQL 查询到 LINQ 语法

转载 作者:太空狗 更新时间:2023-10-29 19:42:24 24 4
gpt4 key购买 nike

我的 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();

获取错误:

Operator '!' cannot be applied to operand of type '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();

关于c# - 使用不存在和连接的 SQL 查询到 LINQ 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36326800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com