linq case insensitive (without toUpper or toLower)

public Articles GetByName(string name, Categories category, Companies company)
{
    var query = from article in session.Linq<Articles>()
                where article.Name == name &&
                      article.Category == category &&
                      article.Company == company
                select article;
    return query.FirstOrDefault();
}

how can query be case insensitive. I can use toLower or toUpper but i want with OrdinalIgnoreCase. Is it possible?


使用String.Equals和适当的参数使其不区分大小写

mySource.Where(s => String.Equals(s, "Foo", StringComparison.CurrentCultureIgnoreCase));

相反,如果==使用.Equals(name, StringComparison.OrdinalIgnoreCase)方法。

var query = from article in session.Linq<Articles>()
            where article.Name.Equals(name, StringComparison.OrdinalIgnoreCase) &&
                  article.Category.Equals(category) &&
                  article.Company.Equals(company)
            select article;

return query.FirstOrDefault();

If this is a LINQ to SQL query against a database with a case-insensitive collation, then it already is case-insensitive. Remember that LINQ to SQL isn't actually executing your == call; it's looking at it as an expression and converting it to an equality operator in SQL.

If it's LINQ to Objects, then you can use String.Equals as the other posters have pointed out.

链接地址: http://www.djcxy.com/p/75230.html

上一篇: Linq不区分大小写加入

下一篇: linq不区分大小写(没有toUpper或toLower)