Subsonic 3.0:如何对物体使用 LIKE?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
更好的方法是:
这将使用特定于提供者的通配符。您还可以使用 StartWith 和 EndWith。
A better way to do it would be:
This will use provider-specific wildcards. You can also use StartsWith and EndWith.
LIKE '%foo%' 用于 TSQL;
对于对象,我们必须使用 LIKE '*foo'
注意:只需将 % 替换为 *;
LIKE '%foo%' is for TSQL;
for objects we have to use LIKE '*foo'
Note: Just replace % with a *;
您可以使用类似于以下内容的内容来构造类似的内容:
不确定它是否是完全正确的代码,但您应该了解要点。
You can construct the like by using something similar to the following:
Not exactly sure if it is exact correct code, but you should get the gist.
我认为 Robs 的回应最有说服力,因为它是独立于提供商的——一般来说,拥有 DAL 的巨大卖点之一就是不被锁定到一个数据库引擎。
坚持:
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: