![]() ![]() But here I’m using its inbuilt functionality. The SQLite.NET provides us with Object Relational Mapping (ORM) that allows us to store and retrieve objects without writing SQL statements. This class will create SQLite connection and the table of our Model class ( Product.cs) which we are using. Public Task deleteProduct(Products product) Public Task saveProduct(Products product) If (!(m => m.MappedType.Name = typeof(Products).Name))Īwait Database.CreateTablesAsync(CreateFlags.None, typeof(Products)).ConfigureAwait(false) InitializeAsync().SafeFireAndForget(false) Static SQLiteAsyncConnection Database => lazyInitializer.Value Return new SQLiteAsyncConnection(Constants.DatabasePath, Constants.Flags) Static readonly Lazy lazyInitializer = new Lazy(() => This class is being called from the main class below, where we are initializing the SQLite connection object. TaskExtensions class will help in creating a database connection in a asynchronous form. Public static async void SafeFireAndForget(this Task task,Īwait task.ConfigureAwait(returnToCallingContext) Ĭatch (Exception ex) when (onException != null) You can change location of the database by editing DatabasePath string as per your requirements. This class contains the name and file path of our SQLite database. Var basePath = Environment.GetFolderPath() Public const SQLite.SQLiteOpenFlags Flags = | Public const string dbName = "Products.db3" Create a folder in your project with name Database and add following classes inside of this folder. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |