RichardS
RichardS

Reputation: 85

How can I get just one field from a database table with SQLite?

I have this class:

public class CarConfiguration : ObservableObject
{
    [PrimaryKey, NotNull]
    public long CarConfigurationId { get; set; }
    public string Name { get; set; }
}

With this code I know I can get all the rows:

public List<CarConfiguration> GetUniqueCarConfigurationNames()
{
   return db2.Table<CarConfiguration>().ToList();
}

But how can I get all the unique names only sorted by name?

Upvotes: 1

Views: 63

Answers (1)

Jason
Jason

Reputation: 89102

use a Query

return db2.Query<string>("select distinct Name from CarConfiguration order by Name").ToList();

Upvotes: 2

Related Questions