用 lambda 表达式连接 3 个表?
我基本上希望将以下 sql 查询作为 lambda 表达式:
SELECT studentname, coursename, grade
FROM student S, course C, grade G
WHERE S.id = G.studentid AND C.coursecode = G.coursecode AND G.grade<='B';
我遇到了麻烦,因为我必须将 3 个表连接在一起。
I basically want the following sql query as a lambda expression:
SELECT studentname, coursename, grade
FROM student S, course C, grade G
WHERE S.id = G.studentid AND C.coursecode = G.coursecode AND G.grade<='B';
I am having trouble as I have to join 3 tables together.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,作为查询表达式,它看起来像这样:(
我通常使用
query
变量名而不是q
- 我刚刚使用了q
此处用于格式化目的。)您可以将其转换为使用 lambda 表达式的显式
Join
调用,但我强烈建议您对复杂查询使用查询表达式像这样。请注意,我更改了查询的顺序,以便尽可能简单有效地表达“where”子句。无论如何,SQL 查询规划器很可能都会对其进行优化,但对于 LINQ to Objects 之类的东西来说,这会有所帮助。
Well, that looks something like this as a query expression:
(I'd normally use a variable name of
query
instead ofq
- I've just usedq
for formatting purposes here.)You could translate this into explicit
Join
calls with lambda expressions, but I'd strongly advise you to use query expressions for complex queries like this.Note that I've changed the order of the query to allow the "where" clause to be expressed as simply and efficiently as possible. In all likelihood a SQL query planner would optimize it anyway, but for something like LINQ to Objects this would help.