Accessing data with SQLite.NET
Many apps need to use databases, whether the app is database-centric or even just to store pieces of data in a structured form. A lightweight ORM can be used to make data access easier.
How to do it...
Accessing the database is very easy when using SQLite.NET, especially since we don't have to write a single line of SQL. Let's take a look at the following steps:
Before we can make use of SQLite.NET, we need to add the component. Right-click on the Components folder in the project and click on Get More Components…. In the dialog that appears, we search for and add the
SQLite.NET
component.Once the component is downloaded, we can start creating the C# types that will represent the tables:
public class MyTable { [AutoIncrement, PrimaryKey] public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } }
Now that we have our tables, we can choose where we want the database to be created to or accessed from:
var databasePath...