【问题标题】:How to do a case insesitive search. Xamarin sqlite如何进行不区分大小写的搜索。 Xamarin sqlite
【发布时间】:2021-02-18 05:22:18
【问题描述】:

下面是我的代码。我正在尝试对描述进行不区分大小写的搜索,它也需要是部分文本搜索,这就是我使用“包含”的原因。

public Task<List<AssetTable>> SearchAssets(int ID, string text)
{
    return _database.Table<AssetTable>()
        .Where(i =>
            (
                i.ParentID == ID ||
                i.Site == ID ||
                i.Location == ID ||
                i.SubLocation == ID ||
                i.PGroup == ID
            ) &&
            i.TempCode == "ASSET" &&
            //i.Description.Contains(text)
            i.Description.Contains(text, StringComparison.CurrentCultureIgnoreCase)
        )
        .ToListAsync();
}

注释的行是我之前的行,但它区分大小写,虽然当前行确实编译和运行,但在搜索文本时出现运行时异常。

[ERROR] FATAL UNHANDLED EXCEPTION: SQLite.SQLiteException: near "?": syntax error
  at SQLite.SQLite3.Prepare2 (SQLitePCL.sqlite3 db, System.String query) [0x0001b] in <84b9c9e630fa45bd8ac799333976ebbf>:0 
  at SQLite.SQLiteCommand.Prepare () [0x00011] in <84b9c9e630fa45bd8ac799333976ebbf>:0 
  at SQLite.SQLiteCommand+<ExecuteDeferredQuery>d__12`1[T].MoveNext () [0x00060] in <84b9c9e630fa45bd8ac799333976ebbf>:0 
  at System.Collections.Generic.List`1[T].AddEnumerable (System.Collections.Generic.IEnumerable`1[T] enumerable) [0x00059] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:1108
  at System.Collections.Generic.List`1[T]..ctor (System.Collections.Generic.IEnumerable`1[T] collection) [0x00062] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:87 
  at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0000e] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Linq/src/System/Linq/ToCollection.cs:30 
  at SQLite.SQLiteCommand.ExecuteQuery[T] () [0x0001c] in <84b9c9e630fa45bd8ac799333976ebbf>:0 
  at SQLite.TableQuery`1[T].ToList () [0x0000b] in <84b9c9e630fa45bd8ac799333976ebbf>:0 
  at SQLite.AsyncTableQuery`1[T].<ToListAsync>b__11_0 (SQLite.SQLiteConnectionWithLock conn) [0x00000] in <84b9c9e630fa45bd8ac799333976ebbf>:0 
  at SQLite.AsyncTableQuery`1+<>c__DisplayClass2_0`1[T,U].<ReadAsync>b__0 () [0x0001d] in <84b9c9e630fa45bd8ac799333976ebbf>:0 
  at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:534 
  at System.Threading.Tasks.Task.Execute () [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319 

不知道我做错了什么,希望能得到帮助和建议以提供更好的解决方案。

【问题讨论】:

    标签: c# sqlite xamarin


    【解决方案1】:

    可能还有其他/更好的解决方案,但我首先要尝试的是这个

    i.Description.ToLower().Contains(text.ToLower())
    

    【讨论】:

    • 不敢相信我没想过要尝试。如果有比将它们都转换为小写更好的解决方案,我会密切关注,但这肯定会给我一个解决方案,谢谢。 :)
    猜你喜欢
    • 2013-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    • 2011-01-18
    • 2013-04-17
    • 2015-09-02
    相关资源
    最近更新 更多