Retrieving data via services
Let’s start retrieving and saving SQLite data with our service methods. It will only be necessary to update the create, update, and delete operations. All the media items are stored in List<MediaItem>
in DataService
, so the public methods used to retrieve items can remain as they were in the previous chapter. Let’s get started:
- Start by updating the create, update, and delete methods for the media items in
SqliteDataService.cs
. Each of these will get an open connection to the database fromGetOpenConnectionAsync
and call its corresponding private method asynchronously:public async Task<int> AddItemAsync(MediaItem item) { using var db = await GetOpenConnectionAsync(); return await InsertMediaItemAsync(db, item); } public async Task UpdateItemAsync(MediaItem item) { using var db = await GetOpenConnectionAsync(); await UpdateMediaItemAsync...