using SalesWebMvc.Models; using System.Linq; public class CustomerService { private readonly SalesWebMvcContext _context; public CustomerService(SalesWebMvcContext context) { _context = context; } public ListGetAllCustomers() { return _context.Customers.ToList(); } }
using SalesWebMvc.Models; public class OrderService { private readonly SalesWebMvcContext _context; public OrderService(SalesWebMvcContext context) { _context = context; } public void AddOrder(Order order) { _context.Orders.Add(order); _context.SaveChanges(); } }This code example demonstrates how to use SalesWebMvcContext to add a new order to the database. The code creates an instance of SalesWebMvcContext and adds the new order object to its Orders property. The SaveChanges() method commits the changes to the database. Package Library: Entity Framework Core.