1
I’m trying to create a method that returns a ObservableCollection
in place of a List
in the 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 on the line that tries to return the list return _database.Table<Tarefa>.ToList();
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. I thank you in advance.