我想花 5-6 个小时来了解有关 GroupJoin 的一些事情。我正在谈论使用 linq 查询数据库表。我了解 Join 和 GroupJoin 的作用,但我真的不明白我在哪里需要它。我觉得 Join 做了我需要的所有事情,但如果有什么 Join 可以'没有 GroupJoin 所以我觉得这种情况毫无意义或无用。
例如:
与 Phones 和 Phones 表相关的 Persons 表包含 Persons 的外键,一个人可以有一个电话号码。如果我们想带来所有有电话号码和没有电话号码的人,那么我们需要 GroupJOin 但是为什么我们需要这个查询?
你能给我使用 GroupJoin 的充分理由、例子或解释吗?
请您参考如下方法:
来自 MSDN:
In relational database terms, Join implements an inner join, a type of join in which only those objects that have a match in the other data set are returned. The GroupJoin method has no direct equivalent in relational database terms, but it implements a superset of inner joins and left outer joins.
因此,如果您曾经有过在 SQL 中使用外部联接的理由,您可能会在 Linq 中出于类似目的使用 GroupJoin。
