Issue
Below is my code. I am trying to get a case insesitive search on Description and it needs to be a partial text search as well which is why I am using the "contains".
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();
}
The commented line is what I had before which works but is case sensitive and while the current line does compile and run, I get and runtime exception upon searching with text.
[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
Not sure what I'm doing wrong and would appreciate the help and suggestions for a better solution.
Solution
there may be other/better solutions, but the first thing I'd try is this
i.Description.ToLower().Contains(text.ToLower())
Answered By - Jason
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.