더북(TheBook)

예제 4-19 Repository 인터페이스의 SQL 서버 구현
(Restaurant/c82d82c/Restaurant.RestApi/SqlReservationsRepository.cs)

public class SqlReservationsRepository : IReservationsRepository
{
    public SqlReservationsRepository( string connectionString)
    {
        ConnectionString = connectionString;
    }

    public string ConnectionString {  get; }

    public async Task Create(Reservation reservation)
    {
        if (reservation  is null)
            throw new ArgumentNullException(nameof(reservation));

        using var conn =  new SqlConnection(ConnectionString);
        using var cmd =  new SqlCommand(createReservationSql, conn);
        cmd.Parameters.Add( new SqlParameter("@At", reservation.At));
        cmd.Parameters.Add( new SqlParameter("@Name", reservation.Name));
        cmd.Parameters.Add( new SqlParameter("@Email", reservation.Email));
        cmd.Parameters.Add(
            new SqlParameter("@Quantity", reservation.Quantity));
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.