Skip to content Skip to sidebar Skip to footer

Select A Table Column From Ienumerable Using Linq

Am having my table as below , by the usage of Sqlite : public class Medication { [PrimaryKey, AutoIncrement] public int ID { get; set; } public string unique_id { get;

Solution 1:

In your select request only that property (and change method return type)

publicIEnumerable<string> AllMedicationResults()
{
    return (from t in _connection.Table<Medication>()
            select t.alarm_time).ToList();
}

But IMO it will look cleaner to just use method syntax:

publicIEnumerable<string> AllMedicationResults()
{
    return  _connection.Table<Medication>().Select(t => t.alarm_time).ToList();
}

Notice that as you are returning an IEnumerable<T> you might want to consider removing the ToList() and using the benefits of linq's deffered execution

Post a Comment for "Select A Table Column From Ienumerable Using Linq"