このコードを使用する場合(「.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();
}
...「タイプ'System.Collections.Generic.List>'を'System.Collections.Generic.List'に暗黙的に変換できません」と表示されます。
これは機能します:
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;
}
...しかし無駄に思えます(GroupName列からの個別の値だけが必要な場合は、すべてのレコードを取得します)。
SQLクエリの「*」を「DISTINCTGroupName」に置き換える場合、必要なのはリストまたはHashSetであるように思われます。
では、複数のレコードから1つの列が返されると、正確には何が返されますか?IOW、QueryAsync <>()の呼び出しの山括弧内に何を含める必要がありますか?
私はこれがうまくいくと思います:
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;
}
...しかし、「文字列」は、ジェネリック型またはメソッド「SQLite.SQLiteAsyncConnection.QueryAsync(string、 params object [])' "
メソッドの作業バージョンの<SOs_Locations
>(「リスト>」ではない)に対応する上記の「文字列」がありました。<SOs_Locations
「リスト>」に変更すると、「タイプ'System.Collections.Generic.List 'を'System.Collections.Generic.List >'に<string
暗黙的に変換できません」というメッセージが表示されます。<System.Collections.Generic.List
<string