/// <summary>
 /// Deprecated Method for adding a new object to the Tags EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToTags(Tag tag)
 {
     base.AddObject("Tags", tag);
 }
 /// <summary>
 /// Create a new Tag object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 public static Tag CreateTag(global::System.Int32 id)
 {
     Tag tag = new Tag();
     tag.ID = id;
     return tag;
 }
        private void saveAnnotation(object state)
        {
            var annotationAndTags = (annotationAndTags)state;

            Annotation annotation = new Annotation() {
                StartIndex = currentSelection.CharIndex,
                SourceLength = currentSelection.CharLength,
                SourceText = currentText.ID,
                Content = annotationAndTags.Annotation,
                Author = currentUser.ID,
                UpVotes = 0,
                DownVotes = 0,
                HighlightedSourceText = string.Concat((this.textRoot.SelectedContent.Content as TextControl).body.Selection.Text.Take(100)),
                Timestamp = DateTime.Now
            };

            db.Annotations.AddObject(annotation);
            db.SaveChanges();

            List<int> tagIDs = new List<int>();
            List<string> inputTags = annotationAndTags.Tags;
            foreach (var tag in inputTags) {
                var resolvedTag = db.Tags.Where(i => i.Name == tag).SingleOrDefault();
                if (resolvedTag == null) {
                    var newTag = new Tag() { Name = tag };
                    db.Tags.AddObject(newTag);
                    db.SaveChanges();
                    tagIDs.Add(newTag.ID);
                } else {
                    tagIDs.Add(resolvedTag.ID);
                }
            }

            foreach (var id in tagIDs) {
                var annotationTag = new AnnotationTag() { AnnotationID = annotation.ID, TagID = id };
                db.AnnotationTags.AddObject(annotationTag);
                db.SaveChanges();
            }

            Dispatcher.Invoke((Action)(() => {
                loadAnnotations();
            }));
        }