C# – Subsonic 3.0: How to use LIKE on objects

clinqsubsonicsubsonic3

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; }
    }

}

Best Answer

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.