I'm trying to create a method that returns a ObservableCollection
instead of a List
in SQLite
namespace Projeto_03.DataBase
{
public class TarefasDataAccess
{
private SQLiteConnection _database;
public TarefasDataAccess()
{
_database = DependencyService.Get<IDatabase>().GetConnection();
_database.CreateTable<Tarefa>();
}
public ObservableCollection<Tarefa> GetTarefas()//era List<Tarefa>
{
return _database.Table<Tarefa>.ToList();
}
}
}
only in the line that tries to return the list return _database.Table<Tarefa>.ToList();
The error occurs:
Error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List<Projeto_03.Model.Tarefa>' to 'System.Collections.ObjectModel.ObservableCollection<Projeto_03.Model.Tarefa>
namespace Projeto_03.ViewModel
{
public partial class TelaPrincipalViewModel : ContentPage
{
public ObservableCollection<Tarefa> Tarefas { get; set; }//era List<Tarefa>
public TelaPrincipalViewModel()
{
Tarefas = new TarefasDataAccess().GetTarefas();
}
}
}
If anyone can help. Thanks in advance.