Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Generic method to load all rows from a table fails

$
0
0

Hi,

I use sqlite-net-pcl nuget package in my project. I have the following generic method to load all rows from a table to an ObservableCollection:

ObservableCollection<T> Load<T>() where T : class, new()
{
    List<T> items = database.Query<T>("SELECT * FROM ?", typeof(T).Name);
    return new ObservableCollection<T>(items);
}

When I try to call it (for example CarList = Load<Car>();), I get an exception (picture attached)

However the following method works without any problem:

ObservableCollection<Car> LoadCars()
{
    List<Car> items = database.Query<Car>("SELECT * FROM Car");
    return new ObservableCollection<Car>(items);
}

Does anybody knows, where is the problem?

Thanks for your help.


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>