linq case insensitive (without toUpper or toLower)

前端 未结 8 2608
执念已碎
执念已碎 2020-12-15 02:27
public Articles GetByName(string name, Categories category, Companies company)
{
    var query = from article in session.Linq()
                where         


        
相关标签:
8条回答
  • 2020-12-15 03:02

    Use string.Equals(name, article.Name, StringComparison.OrdinalIgnoreCase) when you are sure that your database supports it.

    E.g. SQLite with a collate of NOCASE will ignore the option. Oracle uses session settings NLS_COMP, NLS_SORT that will be taken.

    Else use ToLower() or ToUpper() when you have no culture issues.

    0 讨论(0)
  • 2020-12-15 03:04

    Use String.Equals with the appropriate parameters to make it case insensitive

    mySource.Where(s => String.Equals(s, "Foo", StringComparison.CurrentCultureIgnoreCase));
    
    0 讨论(0)
提交回复
热议问题