title: mvc3 with EF code first insert many to many
body: <p>I have a Many to Many relationship defined as</p>
  
  <pre><code>public class Article
      {
          [Required]
          public int Id                                   { get; set; }
  
          [Required]
          public string Title                             { get; set; }
  
          [Required]
          public string Description                       { get; set; }
  
          [Required]
          public string Content                           { get; set; }
  
          [Required]
          public bool IsPublished                         { get; set; }
  
          [Required]
          public DateTime Date                            { get; set; }
  
          [Required]
          public int UserId                               { get; set; }
  
          [Required]
          public double Rating                            { get; set; }
  
          [Required]
          public int RatingCount                          { get; set; }
  
          public virtual User User                        { get; set; }
          public virtual ICollection&lt;Tag&gt;Tags             { get; set; }
          public virtual ICollection&lt;Comment&gt; Comments    { get; set; }
      }
  
  public class Tag
  {
      [Required]
      public int Id      { get; set; }
  
      [Required]
      public string Name { get; set; }
  
      public virtual ICollection&lt;Article&gt; Articles { get; set; }
  }
  </code></pre>
  
  <p>i can easily insert an Article and a tag but when I try to insert </p>
  
  <pre><code>var articles = new List&lt;Article&gt;
              {
                  new Article{ Id = 1, 
                               Date = DateTime.Now, 
                               Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eu molestie eros. Donec sed orci gravida sem ultricies facilisis in ut diam. Quisque at nulla convallis augue congue vehicula quis vel ligula. Ut ultricies massa sit amet sapien commodo eu luctus arcu malesuada. Pellentesque id augue a augue consectetur mattis. Donec id arcu non est suscipit auctor. Donec quis nulla nisl, ut malesuada quam. Donec commodo rh",
                               Content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eu molestie eros. Donec sed orci gravida sem ultricies facilisis in ut diam. Quisque at nulla convallis augue congue vehicula quis vel ligula. Ut ultricies massa sit amet sapien commodo eu luctus arcu malesuada. Pellentesque id augue a augue consectetur mattis. Donec id arcu non est suscipit auctor. Donec quis nulla nisl, ut malesuada quam. Donec commodo rhoncus aliquam. Phasellus suscipit, sem a euismod bibendum, ipsum leo congue dui, eu sollicitudin eros augue ac dui. Suspendisse non tellus mauris, nec vulputate magna. Morbi ac sem felis. Duis facilisis nisl id sapien aliquam sit amet dignissim tellus pretium. Quisque dapibus aliquam sem, sit amet elementum justo fringilla nec. Integer ac arcu sit amet nulla porttitor volutpat. ",                             
                               IsPublished = true,                             
                               Title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
                               UserId = 1,
                               Rating = 0,
                               RatingCount = 0,
                               Tags = new List&lt;Tag&gt;
                               {
                                  new Tag{Id = 1}, 
                                  new Tag{Id = 2}
                               }
  
                  }
              };
              articles.ForEach(s =&gt; dataContext.Article.Add(s));
              dataContext.SaveChanges();
  </code></pre>
  
  <p>i get </p>
  
  <pre>System.Data.Entity.Validation.DbEntityValidationException : Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
  at System.Data.Entity.Internal.InternalContext.SaveChanges()
  at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
  at System.Data.Entity.DbContext.SaveChanges()
  at GigaWebSolutionMVC3Tests.DataBaseHelper.AddArticles(GigaWebSolutionMvc3DataContext dataContext) in DataBaseHelper.cs: line 81
  at GigaWebSolutionMVC3Tests.DataBaseHelper.AddData(GigaWebSolutionMvc3DataContext dataContext) in DataBaseHelper.cs: line 17
  at GigaWebSolutionMVC3Tests.GigaWebSolutionMvc3DataContextTests.Should_be_able_to_add_data_to_the_database() in GigaWebSolutionMVC3DataContextTests.cs: line 41 </pre>
  
  <p>How can I insert the Tags for an article?</p>
  
  <p>Thanks</p>