在ASP.NET MVC中转换查询SQL Server

发布于 2025-02-11 01:52:47 字数 258 浏览 0 评论 0原文

我想在.NET MVC中使用以下SQL Server查询,

select *
from table1
where a = 1
and b not in (select fk_b from table2 where c = 1)

但我不知道如何?

entity.table1.Where(record => record.a== 1 && record ....???

I want to use the SQL Server query below in .NET MVC

select *
from table1
where a = 1
and b not in (select fk_b from table2 where c = 1)

But I don't know how?

entity.table1.Where(record => record.a== 1 && record ....???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柒夜笙歌凉 2025-02-18 01:52:47

在LINQ查询语法中,查询应为:

var result = (
    from a in entity.table1
    where a.a == 1
    and  
    !(
        from b in entity.table2
        where b.c == 1
        select b.fk_b
    ).Contains(a.b)
    select a
).ToList();

在方法表达式中,

var result = entity.table1.Where(record => record.a == 1
    && !entity.table2.Select(y => y.fk_b).Contains(record.b))
    .ToList();

In LINQ query syntax, the query should be:

var result = (
    from a in entity.table1
    where a.a == 1
    and  
    !(
        from b in entity.table2
        where b.c == 1
        select b.fk_b
    ).Contains(a.b)
    select a
).ToList();

While in method expression,

var result = entity.table1.Where(record => record.a == 1
    && !entity.table2.Select(y => y.fk_b).Contains(record.b))
    .ToList();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文