public virtual async Task RemoveAsync(long id, CancellationToken ct = default) { var entity = await FindByIdAsync(id, ct); if (entity == null) { throw new NotFoundException(); } _context.Remove(entity); _context.SaveChanges(); }
//https://exceptionnotfound.net/ef-core-inmemory-asp-net-core-store-database/ public static void Initialize(IServiceProvider serviceProvider) { using (var context = new LavanderiaContext( serviceProvider.GetRequiredService <DbContextOptions <LavanderiaContext> >())) { // Look for any board games. if (context.Usuarios.Any()) { return; // Data was already seeded } context.Usuarios.AddRange( new Usuario { Id = 1, Login = "******", Senha = "Hasbro", }, new Usuario { Id = 2, Login = "******", Senha = "Hasbro", }, new Usuario { Id = 3, Login = "******", Senha = "Days of Wonder", }, new Usuario { Id = 4, Login = "******", Senha = "Catan Studio", }, new Usuario { Id = 5, Login = "******", Senha = "Z-Man Games", }, new Usuario { Id = 6, Login = "******", Senha = "Jax Games", }); context.SaveChanges(); } }
public bool Commit() { return(_context.SaveChanges() > 0); }