コード例 #1
0
 public static Product GetProductById(NorthwindContext dbContext, int id)
 {
     try
     {
         return(GetAllProducts(dbContext).First(product => product.ProductId == id));
     }
     catch (ArgumentNullException ex)
     {
         ex.SetMessage(DbExceptionMessages.FieldIsRequired("id"));
         throw;
     }
     catch (InvalidOperationException ex)
     {
         ex.SetMessage(DbExceptionMessages.InstanceNotFound(InstanceName, id));
         throw;
     }
 }
コード例 #2
0
 public static Customer GetCustomerById(NorthwindContext dbContext, string id)
 {
     try
     {
         return(GetAllCustomers(dbContext).First(customer => customer.CustomerId == id));
     }
     catch (ArgumentNullException ex)
     {
         ex.SetMessage(DbExceptionMessages.FieldIsRequired("id"));
         throw;
     }
     catch (InvalidOperationException ex)
     {
         ex.SetMessage(DbExceptionMessages.InstanceNotFound(InstanceName, id));
         throw;
     }
 }
コード例 #3
0
 public static Employee GetEmployeeById(NorthwindContext dbContext, int id)
 {
     try
     {
         return(GetAllEmployees(dbContext).First(employee => employee.EmployeeId == id));
     }
     catch (ArgumentNullException ex)
     {
         ex.SetMessage(DbExceptionMessages.FieldIsRequired("id"));
         throw;
     }
     catch (InvalidOperationException ex)
     {
         ex.SetMessage(DbExceptionMessages.InstanceNotFound(InstanceName, id));
         throw;
     }
 }