Example #1
0
        public async Task <bool> DeleteAsync(string id, CancellationToken ct = default)
        {
            if (await AnimalExists(id, ct))
            {
                _context.Remove(await _context.Animals.FindAsync(id, ct));

                await _context.SaveChangesAsync(ct);

                return(true);
            }
            return(false);
        }
Example #2
0
        static void DeleteExistingRecord()
        {
            //To edit a record, we first need to get a reference to it; this requires querying the table.
            using PetStoreContext context = new PetStoreContext();
            {
                var squeakyBone = context.Products.Where(p => p.Name == "Squeaky Dog Bone")
                                  .FirstOrDefault();

                //check that a non null object was returned.
                if (squeakyBone is Product)
                {
                    //Remove the object
                    context.Remove(squeakyBone);
                    Console.WriteLine("removed object.");
                }

                //Commit the changes.
                context.SaveChanges();
            }
        }