SubSonic 中的表别名

发布于 2024-08-17 07:07:28 字数 386 浏览 7 评论 0原文

如何使用 SubSonic 2.1 为表分配别名?

我正在尝试重现以下查询:

SELECT *
FROM posts P
RIGHT OUTER JOIN post_meta X ON P.post_id = X.post_id
RIGHT OUTER JOIN post_meta Y ON P.post_id = Y.post_id
WHERE X.meta_key = "category"
    AND X.meta_value = "technology"
    AND Y.meta_key = "keyword"
    AND Y.meta_value = "cloud"

我正在使用 SubSonic 2.1 并且升级到 2.2 还不是一个选项。谢谢。

How can I assign alias to tables with SubSonic 2.1?

I am trying to reproduce the following query:

SELECT *
FROM posts P
RIGHT OUTER JOIN post_meta X ON P.post_id = X.post_id
RIGHT OUTER JOIN post_meta Y ON P.post_id = Y.post_id
WHERE X.meta_key = "category"
    AND X.meta_value = "technology"
    AND Y.meta_key = "keyword"
    AND Y.meta_value = "cloud"

I'm am using SubSonic 2.1 and upgrading to 2.2 isn't an option (yet). Thanks.

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

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

发布评论

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

评论(3

请爱~陌生人 2024-08-24 07:07:28

2.1 中是否存在 CodingHorror 功能?它在文档中声明它属于 2.x 类别。

Does the CodingHorror functionality exist in 2.1? It states on the docs that it's in the 2.x category.

花开半夏魅人心 2024-08-24 07:07:28

使用视图:

CREATE VIEW post_meta2 AS SELECT * FROM post_meta

那么你的查询就变成:

SELECT *
FROM posts
RIGHT OUTER JOIN post_meta ON posts.post_id = post_meta.post_id
RIGHT OUTER JOIN post_meta2 ON posts.post_id = post_meta2.post_id
WHERE post_meta.meta_key = "category"
    AND post_meta.meta_value = "technology"
    AND post_meta2.meta_key = "keyword"
    AND post_meta2.meta_value = "cloud"

是的,我知道,这很粗糙。但还是有效的。如果您想要优雅,请按照已经建议的方式进行升级,否则这对于临时解决方法来说应该足够了。

Use a view:

CREATE VIEW post_meta2 AS SELECT * FROM post_meta

Then your query becomes:

SELECT *
FROM posts
RIGHT OUTER JOIN post_meta ON posts.post_id = post_meta.post_id
RIGHT OUTER JOIN post_meta2 ON posts.post_id = post_meta2.post_id
WHERE post_meta.meta_key = "category"
    AND post_meta.meta_value = "technology"
    AND post_meta2.meta_key = "keyword"
    AND post_meta2.meta_value = "cloud"

Yes, I know, it's crude. But effective nonetheless. If you want elegance then upgrade as has already been suggested, otherwise this should be sufficient for a temporary workaround.

简美 2024-08-24 07:07:28

我认为如果你只使用亚音速 2.2 就可以完成工作。您应该认真考虑升级。 2.2 版本有更多好处,可以让您的生活更美好。

subsonic.select().from("posts p")
        .RightOuterJoin("post_meta","post_id","posts","post_id")
        .RightOuterJoin("post_meta","post_id","posts","post_id")
        .Where("post_meta.meta_key").IsEqualTo("category")
        .And("post_meta.meta_value").IsEqualTo("technology")
        .And("post_meta.meta_key").IsEqualTo("keyword")
        .And("post_meta.meta_value").IsEqualTo("cloud")

I think if you just use in subsonic 2.2 will do the work. You should seriously consider upgrading. Version 2.2 has a lot more goodies to make your life better.

subsonic.select().from("posts p")
        .RightOuterJoin("post_meta","post_id","posts","post_id")
        .RightOuterJoin("post_meta","post_id","posts","post_id")
        .Where("post_meta.meta_key").IsEqualTo("category")
        .And("post_meta.meta_value").IsEqualTo("technology")
        .And("post_meta.meta_key").IsEqualTo("keyword")
        .And("post_meta.meta_value").IsEqualTo("cloud")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文