private void detach_PhotoCategoryJoins(PhotoCategoryJoin entity)
		{
			this.SendPropertyChanging();
			entity.Category = null;
		}
		private void attach_PhotoCategoryJoins(PhotoCategoryJoin entity)
		{
			this.SendPropertyChanging();
			entity.Photo = this;
		}
 partial void DeletePhotoCategoryJoin(PhotoCategoryJoin instance);
 partial void UpdatePhotoCategoryJoin(PhotoCategoryJoin instance);
 partial void InsertPhotoCategoryJoin(PhotoCategoryJoin instance);
        protected void UpdateButton_Click(object sender, System.EventArgs e)
        {
            //    SQLString = "UPDATE Photos SET PhotoDate = #" + DateTime.Parse(PhotoDateTextBox.Text).ToString() + "#, PhotoDescription = '" + PhotoDescriptionTextBox.Text.Replace("'", "''") +
            //    "', PhotoWidth = '" + PhotoWidthTextBox.Text + "', PhotoHeight = '" + PhotoHeightTextBox.Text + "', PhotoResolution = '" + PhotoResolutionTextBox.Text + "', PhotoVisible = " + PhotoVisibleCheckBox.Checked +
            //    " WHERE PhotoID = " + int.Parse(PhotoIDLabel.Text) + " AND PhotoOwner = '" + Session["GalleryOwner"] + "'";
            string ownr = (string)Session["GalleryOwner"];
            Photo toupdate = GDC.Photos.First(phot => phot.PhotoOwner.Equals(ownr) && phot.PhotoID == int.Parse(PhotoIDLabel.Text));

            toupdate.PhotoDate = DateTime.Parse(PhotoDateTextBox.Text);
            toupdate.PhotoDescription = PhotoDescriptionTextBox.Text.Replace("'", string.Empty);
            toupdate.PhotoWidth = short.Parse(PhotoWidthTextBox.Text);
            toupdate.PhotoHeight = short.Parse(PhotoHeightTextBox.Text);
            toupdate.PhotoResolution = short.Parse(PhotoResolutionTextBox.Text);
            toupdate.PhotoVisible = PhotoVisibleCheckBox.Checked;

            GDC.SubmitChanges();

            //Clear and reassign the categories
            //SQLString = "DELETE FROM PhotosJoinCategories WHERE PhotoNumber=" + int.Parse(PhotoIDLabel.Text);
            IEnumerable<PhotoCategoryJoin> todelete =
                from pcj in GDC.PhotoCategoryJoins
                where pcj.PhotoNumber == int.Parse(PhotoIDLabel.Text)
                select pcj;
            if (todelete != null)
            {
                GDC.PhotoCategoryJoins.DeleteAllOnSubmit(todelete);
                GDC.SubmitChanges();
            }
            //Stub statement, needs more OR's to get anything
            //SQLString = "INSERT INTO PhotosJoinCategories ( CategoryNumber, PhotoNumber ) SELECT CategoryID, " + int.Parse(PhotoIDLabel.Text) + " FROM Categories WHERE CategoryID = 0";
            List<PhotoCategoryJoin> pcjlist = new List<PhotoCategoryJoin>();
            PhotoCategoryJoin pcjoin;
            for (int i = 0; i <= AllCategoriesList.Items.Count - 1; i++)
            {
                if (AllCategoriesList.Items[i].Selected)
                {
                    //SQLString = SQLString + " OR CategoryID = " + AllCategoriesList.Items[i].Value;
                    pcjoin = new PhotoCategoryJoin();
                    pcjoin.PhotoNumber = int.Parse(PhotoIDLabel.Text);
                    pcjoin.CategoryNumber = int.Parse(AllCategoriesList.Items[i].Value);
                    pcjlist.Add(pcjoin);
                }
            }
            GDC.PhotoCategoryJoins.InsertAllOnSubmit(pcjlist);
            GDC.SubmitChanges();

            //If it's already Flickr'ed, mark it for an update on the next sweep
            //SQLString = "INSERT INTO FlickrCommands ( FlickrCommandType, FlickrCommandPhoto )
            //SELECT 'UpdatePhoto', Photos.PhotoID FROM Photos WHERE PhotoFlickrID Is Not Null AND PhotoID=" + int.Parse(PhotoIDLabel.Text) + " AND PhotoOwner = '" + Session["GalleryOwner"] + "'";
            IEnumerable<int> flickrphotos =
                from photo in GDC.Photos
                where (photo.PhotoFlickrID != null) && photo.PhotoID == int.Parse(PhotoIDLabel.Text) && photo.PhotoOwner.Equals((string)Session["GalleryOwner"])
                select photo.PhotoID;
            if (flickrphotos.Count() != 0)
            {
                int flickrphoto = flickrphotos.First();
                FlickrCommand fc = new FlickrCommand();
                fc.FlickrCommandType = "UpdatePhoto";
                fc.FlickrCommandPhoto = flickrphoto;
                GDC.FlickrCommands.InsertOnSubmit(fc);
                GDC.SubmitChanges();
            }
            LoadPictureData();
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", "<script type=\"text/javascript\">window.opener.location.href = window.opener.location.href;window.close();</script>");
        }