实体框架 - 为什么 EF 在一对一关系中使用 LEFT OUTER JOIN?
为什么 .NET 实体框架生成在简单的一对一关系上使用子查询和左外连接的 SQL?我期望在两个表上看到一个简单的连接。我正在使用 Devart Dotconnect for Oracle。有什么想法吗?
下面是我看到的输出,由 EFTracingProvider:
SELECT
1 AS C1,
"Join1".USER_ID1 AS USER_ID,
...
FROM "MY$NAMESPACE".MYTABLE1 "Extent1"
INNER JOIN (...
FROM "MY$NAMESPACE".MYTABLE2 "Extent2"
LEFT OUTER JOIN "MY$NAMESPACE".MYTABLE1 "Extent3" ON "Extent2".OTHER_ID = "Extent3".OTHER_ID )
"Join1" ON "Extent1".OTHER_ID = "Join1".OTHER_ID1
WHERE "Extent1".USER_ID = :EntityKeyValue1
-- EntityKeyValue1 (dbtype=String, size=6, direction=Input) = "000000"
Why does .NET Entity Framework produce SQL that uses a subquery and left outer join on a simple 1-to-1 relationship? I expected to see a simple join on the two tables. I'm using Devart Dotconnect for Oracle. Any ideas?
Below is the output I see courtesy of the EFTracingProvider:
SELECT
1 AS C1,
"Join1".USER_ID1 AS USER_ID,
...
FROM "MY$NAMESPACE".MYTABLE1 "Extent1"
INNER JOIN (...
FROM "MY$NAMESPACE".MYTABLE2 "Extent2"
LEFT OUTER JOIN "MY$NAMESPACE".MYTABLE1 "Extent3" ON "Extent2".OTHER_ID = "Extent3".OTHER_ID )
"Join1" ON "Extent1".OTHER_ID = "Join1".OTHER_ID1
WHERE "Extent1".USER_ID = :EntityKeyValue1
-- EntityKeyValue1 (dbtype=String, size=6, direction=Input) = "000000"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在数据库理论中,假设在一对一关系中,一侧的行必须在另一侧的相应行之前创建。如果您不使用外连接,那么您将永远无法列出不匹配的行。
In database theory, it is assumed that in a one-to-one relationship, A row on one side must be created before the corresponding row on the other side. If you didn't use an outer join, then you could never list the rows which had no match.