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


FLASHBACK WITH SIRASA FM AT GALGAMUWA 2022


Mp3 Download: Mdu - Mazola


Imitation gun was fired at motorist in Leicester road-rage incident


Ndebele names


MCKINNEY EMALINE “EMMA” OF WES...


Okra & Motia — The Workshop (Prod by Hammer)


Skint TV teen to be sentenced


Moondru Mudichu 19-09-2017 – Polimer tv Serial


YOSVANI JAMES Arrested by Miami-Dade County Corrections on Jan 10, 2017


Stories • Goddess Stepmom



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