//Insert the performance into the db, and generate a new Id for it.
        public int Insert()
        {
            try
            {
                using (MusicEntities dc = new MusicEntities())
                {
                    //Create a new Id
                    this.Id = Guid.NewGuid();

                    //Set the properties
                    tblPerformancePiece performancePiece = new tblPerformancePiece
                    {
                        Id            = this.Id,
                        Notes         = this.Notes,
                        MP3Path       = this.MP3Path,
                        GroupId       = this.GroupId,
                        PerformanceId = this.PerformanceId,
                        DirectorId    = this.DirectorId,
                        PieceId       = this.PieceId
                    };

                    //Add it to the table and save changes
                    dc.tblPerformancePieces.Add(performancePiece);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //Retrieve the performance from the database with this Id
        public void LoadById()
        {
            try
            {
                using (MusicEntities dc = new MusicEntities())
                {
                    //Retrieve from the db
                    tblPerformancePiece performancepiece = dc.tblPerformancePieces.FirstOrDefault(p => p.Id == this.Id);

                    //Set this performancepiece's properties
                    this.Notes         = performancepiece.Notes;
                    this.MP3Path       = performancepiece.MP3Path;
                    this.GroupId       = performancepiece.GroupId != null ? performancepiece.GroupId : Guid.Empty;
                    this.PieceId       = performancepiece.PieceId != null ? performancepiece.PieceId : Guid.Empty;
                    this.PerformanceId = performancepiece.PerformanceId != null ? performancepiece.PerformanceId : Guid.Empty;
                    if (performancepiece.DirectorId.HasValue)
                    {
                        this.DirectorId = performancepiece.DirectorId.Value;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public int Update()
        {
            try
            {
                using (MusicEntities dc = new MusicEntities())
                {
                    //Retrieve the record from the DB
                    tblPerformancePiece performancePiece = dc.tblPerformancePieces.FirstOrDefault(c => c.Id == this.Id);

                    //Update the properties
                    performancePiece.Notes         = this.Notes;
                    performancePiece.MP3Path       = this.MP3Path;
                    performancePiece.GroupId       = this.GroupId;
                    performancePiece.DirectorId    = this.DirectorId;
                    performancePiece.PieceId       = this.PieceId;
                    performancePiece.PerformanceId = this.PerformanceId;

                    //Save the changes
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void DeleteTest()
        {
            using (MusicEntities dc = new MusicEntities())
            {
                tblPerformancePiece performancepiece = dc.tblPerformancePieces.FirstOrDefault(a => a.Notes == "PL Test");

                dc.tblPerformancePieces.Remove(performancepiece);

                dc.SaveChanges();

                tblPerformancePiece retrievedPerformancePiece = dc.tblPerformancePieces.FirstOrDefault(a => a.Notes == "PL Test");

                Assert.IsNull(retrievedPerformancePiece);
            }
        }
        public void UpdateTest()
        {
            using (MusicEntities dc = new MusicEntities())
            {
                tblPerformancePiece performancepiece = dc.tblPerformancePieces.FirstOrDefault(a => a.Notes == "PL Test");

                performancepiece.MP3Path = "PL Updated Test";

                dc.SaveChanges();

                tblPerformancePiece retrievedPerformancePiece = dc.tblPerformancePieces.FirstOrDefault(a => a.Notes == "PL Test");

                Assert.IsNotNull(retrievedPerformancePiece);
            }
        }
        public int Delete()
        {
            try
            {
                using (MusicEntities dc = new MusicEntities())
                {
                    //Retrieve it from the DB
                    tblPerformancePiece performancePiece = dc.tblPerformancePieces.FirstOrDefault(p => p.Id == this.Id);

                    //Remove the performance
                    dc.tblPerformancePieces.Remove(performancePiece);

                    //Save the changes
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void InsertTest()
        {
            using (MusicEntities dc = new MusicEntities())
            {
                tblPerformancePiece performancepiece = new tblPerformancePiece();
                performancepiece.Id            = Guid.NewGuid();
                performancepiece.DirectorId    = dc.tblDirectors.FirstOrDefault(p => p.FirstName == "Broderick").Id;
                performancepiece.GroupId       = dc.tblGroups.FirstOrDefault(p => p.Name == "Jazz Ensemble").Id;
                performancepiece.PerformanceId = dc.tblPerformances.FirstOrDefault(p => p.Name == "Spring Concert").Id;
                performancepiece.PieceId       = dc.tblPieces.FirstOrDefault(p => p.Name == "Rock Music").Id;
                performancepiece.Notes         = "PL Test";
                performancepiece.MP3Path       = "PL Test";

                dc.tblPerformancePieces.Add(performancepiece);

                dc.SaveChanges();

                tblPerformancePiece retrievedPerformancePiece = dc.tblPerformancePieces.FirstOrDefault(a => a.Notes == "PL Test");

                Assert.AreEqual(performancepiece.Id, retrievedPerformancePiece.Id);
            }
        }