예제 #1
0
        public Movie FirstOrDefault(int ID)
        {
            using (var conn = new SqlConnection(_ConnectionString))
            {
                conn.Open();
                var helper = new DbHelperSql(conn);

                string sql     = @"
select  ID, Genre, Price, ReleaseDate, Title
from    Movie
where   ID = @ID
";
                var    paramIn = new SqlParameter("@ID", ID);
                var    reader  = helper.ExecReaderSql(sql, paramIn);
                if (!reader.HasRows)
                {
                    return(null);
                }

                reader.Read();
                return(new Movie()
                {
                    Id = reader.GetInt32("ID"),
                    Genre = reader.GetString("Genre"),
                    Price = reader.GetDecimal("Price"),
                    ReleaseDate = reader.GetDateTime("ReleaseDate"),
                    Title = reader.GetString("Title"),
                });
            }
        }