linq中的Where和Join之间有什么区别? [英] What is difference between Where and Join in linq?

查看:345
本文介绍了linq中的Where和Join之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个查询之间有什么区别?他们是完全平等的吗?

What is difference between of these 2 queries ? they are completely equal ?

from order in myDB.OrdersSet
    from person in myDB.PersonSet
    from product in myDB.ProductSet
    where order.Persons_Id==person.Id && order.Products_Id==product.Id
    select new { order.Id, person.Name, person.SurName,  product.Model,UrunAdı=product.Name };

from order in myDB.OrdersSet
    join person in myDB.PersonSet on order.Persons_Id equals person.Id
    join product in myDB.ProductSet on order.Products_Id equals product.Id
    select new { order.Id, person.Name, person.SurName,  product.Model,UrunAdı=product.Name };

推荐答案

最终结果应该相同.

但是使用JOIN更清楚-您正在做什么(加入三组数据)更加明显.

But using JOIN is clearer - it's more obvious what you're doing (joining three sets of data).

我个人的最佳实践"方法是:

My personal "best practice" approach would be:

  • 使用WHERE减少并限制返回的行数-通常限制一组数据(通过定义一些要满足的条件)

  • use WHERE to reduce and limit the number of rows returned - it's typically limiting one set of data (by defining some criteria to be met)

使用JOIN表示将两个表/数据集在一个公共字段(或一组字段)上连接在一起的意图

use JOIN to express the intent of joining two tables / sets of data together on a common field (or set of fields)

这篇关于linq中的Where和Join之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆