views:

27

answers:

3

Here is my current code for searching tags:

    public JsonResult TagSearch(string term) {
        if (term == null || term == "")
            return Json("");

        var tags = (from t in _session.All<Tag>() where t.Name.Contains(term) select t.Name).Take(6).ToArray();

        return Json(tags);
    }

How could I do case insensitive string search instead?

A: 

Is changing the collation of the column out of the question?

Dismissile
A: 

The Contains() method is converted to case-insensitive operation in SQL. I think the code I posted is case insensitive.

randomguy
A: 

Use the ToLower method. Like this:

var tags = (from t in _session.All<Tag>() where t.Name.ToLower().Contains(term.ToLower()) select t.Name).Take(6).ToArray();
Martin Ingvar Kofoed Jensen