![]() In Solution Explorer, in the Notes project, expand NotesPage.xaml in the Views folder and open. The advantage of exposing the database as a singleton is that a single database connection is created that's kept open while the application runs, therefore avoiding the expense of opening and closing the database file each time a database operation is performed. This code defines a Database property that creates a new NoteDatabase instance as a singleton, passing in the filename of the database as the argument to the NoteDatabase constructor. Create the database connection as a singleton.ĭatabase = new NoteDatabase(Path.Combine(Environment.GetFolderPath(), "Notes.db3")) Then replace the existing code with the following code: using System In Solution Explorer, in the Notes project, expand App.xaml and double-click to open it. Save the changes to NoteDatabase.cs by pressing CTRL+S. This path will be provided by the App class in the next step. In addition, the NoteDatabase constructor takes the path of the database file as an argument. The code uses asynchronous SQLite.NET APIs that move database operations to background threads. This class contains code to create the database, read data from it, write data to it, and delete data from it. In NoteDatabase.cs, replace the existing code with the following code: using ĭatabase = new SQLiteAsyncConnection(dbPath) In Solution Explorer, in the Notes project, add a new class named NoteDatabase to the Data folder. In Solution Explorer, add a new folder named Data to the Notes project. The application will not currently build due to errors that will be fixed in subsequent steps.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |