Subsonic 3.0:如何对物体使用 LIKE?

发布于 2024-08-03 12:04:35 字数 610 浏览 8 评论 0原文

Subsonic 3.0 的新手,想知道如何对对象属性执行 LIKE 运算符。给定以下课程,我将如何使用 Subsonic 3.0 执行 LIKE 操作。例如 SELECT * FROMcategories WHERE name LIKE '%foo%';

public class Category
{
    private String categoryID;
    private String name;

    public Category()
    {
        //  Do Nothing
    }

    public Category(String name)
    {
        this.Name = name;
    }

    public string CategoryID
    {
        get { return this.categoryID; }
        set { this.categoryID = value; }
    }

    public string Name
    {
        get { return this.name; }
        set { this.name = value; }
    }

}

New to Subsonic 3.0 and wondering how to perform LIKE operators on object attributes. Given the following class, how would I perform a LIKE operation using Subsonic 3.0. For example SELECT * FROM categories WHERE name LIKE '%foo%';

public class Category
{
    private String categoryID;
    private String name;

    public Category()
    {
        //  Do Nothing
    }

    public Category(String name)
    {
        this.Name = name;
    }

    public string CategoryID
    {
        get { return this.categoryID; }
        set { this.categoryID = value; }
    }

    public string Name
    {
        get { return this.name; }
        set { this.name = value; }
    }

}

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

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

发布评论

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

评论(4

冷了相思 2024-08-10 12:04:35

更好的方法是:

return new SubSonic.Select().From(Categories.Schema)
   .Where(Categories.name).Contains("foo")
   .ExecuteTypedList<Categories>();

这将使用特定于提供者的通配符。您还可以使用 StartWith 和 EndWith。

A better way to do it would be:

return new SubSonic.Select().From(Categories.Schema)
   .Where(Categories.name).Contains("foo")
   .ExecuteTypedList<Categories>();

This will use provider-specific wildcards. You can also use StartsWith and EndWith.

世俗缘 2024-08-10 12:04:35

LIKE '%foo%' 用于 TSQL;
对于对象,我们必须使用 LIKE '*foo'

注意:只需将 % 替换为 *;

LIKE '%foo%' is for TSQL;
for objects we have to use LIKE '*foo'

Note: Just replace % with a *;

九命猫 2024-08-10 12:04:35

您可以使用类似于以下内容的内容来构造类似的内容:

var keyword = "foo";

return new SubSonic.Select().From(Categories.Schema)
   .Where(Categories.name).Like("%" + keyword + "%")
   .ExecuteTypedList<Categories>();

不确定它是否是完全正确的代码,但您应该了解要点。

You can construct the like by using something similar to the following:

var keyword = "foo";

return new SubSonic.Select().From(Categories.Schema)
   .Where(Categories.name).Like("%" + keyword + "%")
   .ExecuteTypedList<Categories>();

Not exactly sure if it is exact correct code, but you should get the gist.

猫烠⑼条掵仅有一顆心 2024-08-10 12:04:35

我认为 Robs 的回应最有说服力,因为它是独立于提供商的——一般来说,拥有 DAL 的巨大卖点之一就是不被锁定到一个数据库引擎。

坚持:

.Contains()

I think Robs response holds the most water as it is provider independant - one of the huge selling points of having a DAL in general is not being locked to one database engine.

Stick with:

.Contains()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文