With this code (with or without .ToList () "):
public async Task<List<String>> SelectDistinctGroupNames() { var db = new SQLiteAsyncConnection(SQLitePath); var groupNames = await db.QueryAsync<List<string>>("SELECT DISTINCT GroupName FROM SOs_Locations"); return groupNames.ToList(); }
... I get: "It is not possible to implicitly convert the type" System.Collections.Generic.List> "to" System.Collections.Generic.List "
It works:
public async Task<HashSet<String>> SelectDistinctGroupNames() { var db = new SQLiteAsyncConnection(SQLitePath); var allLocations = await db.QueryAsync<SOs_Locations>("SELECT * FROM SOs_Locations ORDER BY GroupName"); HashSet<string> hashsetGroupNames = null; foreach (var item in allLocations) { hashsetGroupNames.Add(item.GroupName); } return hashsetGroupNames; }
... but it seems wasteful (capturing all the records when all I need is different values ββfrom the GroupName column).
It seems to me that you need a List or even a HashSet when replacing "*" in the sql query "DISTINCT GroupName"
So what exactly is returned when a single column of multiple records is returned? IOW, what should be in the angle brackets of the QueryAsync <> () call?
I would think this would work:
public async Task<List<String>> SelectDistinctGroupNames() { var db = new SQLiteAsyncConnection(SQLitePath); List<string> allLocations = await db.QueryAsync<string>("SELECT DISTINCT GroupName FROM SOs_Locations ORDER BY GroupName"); return allLocations; }
... but with this I get: "String" should not be an abstract type with an open constructor without parameters, to use it as a parameter "T" in the generic type or method "SQLite.SQLiteAsyncConnection.QueryAsync (string, params object []) '"
I had a "string" above to match <SOs_Locations > (not "List <SOs_Locations >") in the working version of the method. When I change it to "List <string >", I get: "It is not possible to implicitly convert the type" System.Collections.Generic.List <System.Collections.Generic.List "to" System.Collections.Generic.List <string > " "
source share