title: How does Linq return an anonymous type of IQueryable to get its record count?
body: <p>The following Linq query returns an IQueryable of anonymous type:</p>
  
  <pre><code>var users2 = from u1 in Users
           join u2 in distribs on u1.pDistribId equals u2.Id
           into temp
           from u3 in temp.DefaultIfEmpty()
           select new {
               u1.Id,
               u1.UserName,
               u1.pDistribId,
               pUserName = u3 == null ? "" : u3.UserName,
               u1.Phone,
               u1.Name,
               u1.pCustomUser,
               u1.CoName,
               u1.CoPhone,
               u1.Birthday,
               u1.QQ,
               u1.Email,
               u1.SelfIntr
           };
  </code></pre>
  
  <p>To get the number of records for users2, use the following method:</p>
  
  <pre><code>var c = users2.Count();
  </code></pre>
  
  <p>Error in result:</p>
  
  <blockquote>
    <p>Dbcomparonexpression requires parameters of a comparable type.</p>
  </blockquote>
  
  <p>How does an IQueryable type like this anonymous type get its record count?</p>
  
  <p>Complete source code：</p>
  
  <p>users：</p>
  
  <pre><code>var Users = from u in UserManager.Users
                          where u.Equals("user")
                          select new { u.Id, u.UserName, u.pDistribId, u.Phone, u.Name, u.CoName, u.CoPhone, u.pCustomUser, u.Birthday, u.QQ, u.Email, u.SelfIntr };
  </code></pre>
  
  <p>distribs：</p>
  
  <pre><code>var distribs = from u in UserManager.Users
                             where u.Role.Equals("distrib")
                             select new { u.Id, u.UserName, u.pDistribId, u.Phone, u.Name, u.CoName, u.CoPhone, u.pCustomUser, u.Birthday, u.QQ, u.Email, u.SelfIntr };
  </code></pre>
  
  <p>users2:</p>
  
  <pre><code>var users2 = (from u1 in Users
               join u2 in distribs on u1.pDistribId equals u2.Id
               into temp
               from u3 in temp.DefaultIfEmpty()
               select new {
                   u1,
                   u3
               }).ToList()
               .Select(x =&gt; new {
                   x.u1.Id,
                   x.u1.UserName,
                   x.u1.pDistribId,
                   pUserName = x.u3 == null ? "" : x.u3.UserName,
                   x.u1.Phone,
                   x.u1.Name,
                   x.u1.pCustomUser,
                   x.u1.CoName,
                   x.u1.CoPhone,
                   x.u1.Birthday,
                   x.u1.QQ,
                   x.u1.Email,
                   x.u1.SelfIntr
               });
  
  
  var c = users2.Count();
  </code></pre>
  
  <p>In this code Still report the same error：</p>
  
  <p><code>var users2 = (from u1 in Users</code></p>