[英]Subsonic 3.0: How to use LIKE on objects?
New to Subsonic 3.0 and wondering how to perform LIKE operators on object attributes. Subsonic 3.0的新功能,想知道如何对对象属性执行LIKE运算符。 Given the following class, how would I perform a LIKE operation using Subsonic 3.0.
给定以下课程,我将如何使用Subsonic 3.0执行LIKE操作。 For example SELECT * FROM categories WHERE name LIKE '%foo%';
例如SELECT * FROM类别,其中名称类似于'%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; }
}
} }
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.
您也可以使用StartsWith和EndWith。
LIKE '%foo%' is for TSQL; LIKE'%foo%'用于TSQL; for objects we have to use LIKE '*foo'
对于对象,我们必须使用LIKE'* foo'
Note: Just replace % with a *; 注意:只需将%替换为*;
You can construct the like by using something similar to the following: 您可以使用类似于以下内容的方法来构造like:
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. 不完全确定这是否是正确的代码,但是您应该明白要点。
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. 我认为Robs响应最受支持,因为它独立于提供程序-总体而言,拥有DAL的巨大卖点之一就是没有被锁定在一个数据库引擎上。
Stick with: 坚持:
.Contains()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.