哪里 vs 加入。哪一个更好用

发布于 2024-12-26 12:21:45 字数 643 浏览 2 评论 0原文

目前我正在运行一些代码并对此有一些疑问。下面是两个 LINQ to Entites 查询的代码清单。

代码清单 A:

IQueryable list = 
    from tableProject in db.Project 
    select new {StaffInCharge = (
        from tableStaff in db.Staff
        where tableStaff.StaffId == tableProject.StaffInChargeId 
        select tableStaff.StaffName)};

代码清单 B:

IQueryable list = 
    from tableProjectin db.Project 
    join tableStaff in db.Staff
        on tableProject.StaffInChargeId
        equal tableStaff.StaffId
    select new {StaffInCharge = tableStaff.StaffName};

我想弄清楚的是,如果我必须从许多其他表中选择许多列,哪一个会更好更快。

谢谢。

Currently I'm running some code and got some question about this. Below are the code listings of two LINQ to Entites queries.

Code listing A:

IQueryable list = 
    from tableProject in db.Project 
    select new {StaffInCharge = (
        from tableStaff in db.Staff
        where tableStaff.StaffId == tableProject.StaffInChargeId 
        select tableStaff.StaffName)};

Code listing B:

IQueryable list = 
    from tableProjectin db.Project 
    join tableStaff in db.Staff
        on tableProject.StaffInChargeId
        equal tableStaff.StaffId
    select new {StaffInCharge = tableStaff.StaffName};

What I want to figure out is which one will be better and faster if I have to select many column from many others table.

Thanks.

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

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

发布评论

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

评论(1

醉生梦死 2025-01-02 12:21:45

这是@Tim Schmelter 的评论

“这篇文章(实际上是我的问题)与基于 LINQ-To-Objects 的 LINQ-To-DataSet 相关。Linq to SQL 或 Linq to Entities 可能会通过以下方式进行优化: DBMS 以这种方式使 where 子句具有与联接相同的性能。”

并且链接是
为什么 LINQ JOIN 比链接快得多哪里?
我认为这非常有用。

this is the comment from @Tim Schmelter

"The article(actually my SO-Question) relates to LINQ-To-DataSet what is based on LINQ-To-Objects. Linq to SQL or Linq to Entities might be optimized by the DBMS in that way that a where clause has the same performance as a join."

and the link is
Why is LINQ JOIN so much faster than linking with WHERE?
i think it is very useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文