How does an IQueryable whose Linq returns an anonymous type get its number of records?

the following Linq query returns IQueryable of anonymous type:

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
             };

if you want to get the number of records of users2, use the following method to get the number of records

var c = users2.Count();

will prompt an error:

DbComparisonExpression requires parameters of comparable types.

Debug view as follows:

how does an IQueryable type like this anonymous type get its number of records?


try ToList () first and then call the method to get the quantity.

Menu