private static void Repository() { IBeerRepository repo = Database.As<IBeerRepository>(); // single object operations Beer b = new Beer() { Name = "Double IPA", Flavor = "IPA" }; repo.InsertBeer(b); b.Name = "Tripel IPA"; repo.UpdateBeer(b); repo.UpsertBeer(b); int totalRows; var results = repo.FindBeersByFlavor("IPA", out totalRows); repo.DeleteBeer(b.Id); // multiple object operations Beer b2 = new Beer() { Name = "Tripel IPA" }; Beer b3 = new Beer() { Name = "Quad IPA (eek!)" }; List<Beer> beers = new List<Beer>() { b, b2 }; repo.InsertBeers(beers); beers.Add(b3); repo.UpsertBeers(beers); // wildcard find IList<Beer> ipas = repo.FindBeers(new { Name = "%IPA%", NameOperator = "LIKE" }); Console.WriteLine("There are {0} IPAs in the database", ipas.Count); // clean up repo.DeleteBeers(beers.Select(beer => beer.Id)); // create a receipt Receipt r = new Receipt() { Id = 1, Name = "John Smith" }; repo.UpsertReceipt(r); repo.DeleteReceipt(r.Id); }
/// <summary> /// Asynchronously updates a single Receipt in the repository. /// </summary> /// <param name="receipt">The Receipt to upsert.</param> /// <returns>A task representing the completion of the operation.</returns> public Task UpsertReceiptAsync(Receipt receipt) { return _connectionFactory().InsertAsync("UpsertReceipt", receipt); }
/// <summary> /// Upserts a single Receipt in the repository. /// </summary> /// <param name="receipt">The Receipt to update.</param> public void UpsertReceipt(Receipt receipt) { _connectionFactory().Insert("UpsertReceipt", receipt); }
/// <summary> /// Asynchronously updates a single Receipt in the repository. /// </summary> /// <param name="receipt">The Receipt to update.</param> /// <returns>A task representing the completion of the operation.</returns> public Task UpdateReceiptAsync(Receipt receipt) { return _connectionFactory().ExecuteAsync("UpdateReceipt", receipt); }
/// <summary> /// Updates a single Receipt in the repository. /// </summary> /// <param name="receipt">The Receipt to update.</param> public void UpdateReceipt(Receipt receipt) { _connectionFactory().Execute("UpdateReceipt", receipt); }