title: Check if two lists are equal
body: <p>I have a class as follows:</p>
  <pre><code>public class Tag {
      public Int32 Id { get; set; }
      public String Name { get; set; }
  }
  </code></pre>
  <p>And I have two lists of tag:</p>
  <pre><code>List&lt;Tag&gt; tags1;
  List&lt;Tag&gt; tags2;
  </code></pre>
  <p>I used <a href="http://en.wikipedia.org/wiki/Language_Integrated_Query" rel="noreferrer">LINQ</a>'s select to get the Ids of each tags list. And then:</p>
  <pre><code>List&lt;Int32&gt; ids1 = new List&lt;Int32&gt; { 1, 2, 3, 4 };
  List&lt;Int32&gt; ids2 = new List&lt;Int32&gt; { 1, 2, 3, 4 };
  List&lt;Int32&gt; ids3 = new List&lt;Int32&gt; { 2, 1, 3, 4 };
  List&lt;Int32&gt; ids4 = new List&lt;Int32&gt; { 1, 2, 3, 5 };
  List&lt;Int32&gt; ids5 = new List&lt;Int32&gt; { 1, 1, 3, 4 };
  </code></pre>
  <p>ids1 should be equal to ids2 and ids3 ... Both have the same numbers.</p>
  <p>ids1 should not be equal to ids4 and to ids5 ...</p>
  <p>I tried the following:</p>
  <pre><code>var a = ints1.Equals(ints2);
  var b = ints1.Equals(ints3);
  </code></pre>
  <p>But both give me false.</p>
  <p>What is the fastest way to check if the lists of tags are equal?</p>
  <p><strong>UPDATE</strong></p>
  <p>I am looking for POSTS which TAGS are exactly the same as the TAGS in a BOOK.</p>
  <pre><code>IRepository repository = new Repository(new Context());
  
  IList&lt;Tags&gt; tags = new List&lt;Tag&gt; { new Tag { Id = 1 }, new Tag { Id = 2 } };
  
  Book book = new Book { Tags = new List&lt;Tag&gt; { new Tag { Id = 1 }, new Tag { Id = 2 } } };
  
  var posts = repository
    .Include&lt;Post&gt;(x =&gt; x.Tags)
    .Where(x =&gt; new HashSet&lt;Int32&gt;(tags.Select(y =&gt; y.Id)).SetEquals(book.Tags.Select(y =&gt; y.Id)))
    .ToList();
  </code></pre>
  <p>I am using <a href="http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework" rel="noreferrer">Entity Framework</a> and I get the error:</p>
  <blockquote>
  <p>An exception of type 'System.NotSupportedException' occurred in mscorlib.dll but was not handled in user code</p>
  <p>Additional information: LINQ to Entities does not recognize the method 'Boolean SetEquals(System.Collections.Generic.IEnumerable`1[System.Int32])' method, and this method cannot be translated into a store expression.</p>
  </blockquote>
  <p>How do I solve this?</p>