如何使用Linq和SQL Server执行不区分大小写的字符串搜索? [英] How can I do case insensitive string search with Linq and SQL Server?

查看:104
本文介绍了如何使用Linq和SQL Server执行不区分大小写的字符串搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我当前用于搜索标签的代码:

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?

推荐答案

在SQL中,Contains()方法将转换为不区分大小写的操作.我认为我发布的代码 不区分大小写.

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

这篇关于如何使用Linq和SQL Server执行不区分大小写的字符串搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆